在XSLT中有
<xsl:value-of select="expression"/>
Run Code Online (Sandbox Code Playgroud)
获取元素的值,但是有什么东西可以选择元素的标记名吗?
在这种情况下:
<person>
<!-- required stuff -->
<name>Robert</name>
<!-- optional stuff, free form for future extension.
Using XMLSchema's xsd:any -->
<profession>programmer</profession>
<hobby>photography</hobby>
</person>
<xsl:for-each select="person">
<xsl:tag-of select="."/> : <xsl:value-of select="."/>
</xsl:for-each>
Run Code Online (Sandbox Code Playgroud)
要获得这样的输出:
Run Code Online (Sandbox Code Playgroud)name : Robert profession : programmer hobby : photography
当然上面的XSLT不会编译因为
<xsl:tag-of select="expression"/>
Run Code Online (Sandbox Code Playgroud)
不存在.但是怎么办呢?
.NET 3.5并不完全支持XPATH 2.0或XSLT 2.0,这太糟糕了.有谁知道这两个将在未来的.NET版本中被包含和完全支持吗?
我们在办公室中使用的程序通过将使用XSLT文件导出的XML文件转换为XHTML来导出报告.我正在重写XSLT以更改格式并从源XML文件中添加更多信息.
我想在最终报告中包含文件的创建日期.但是当前日期/时间不包含在原始XML文件中,也无法控制XML文件的创建方式.似乎没有任何构建到XSLT中的日期函数将返回当前日期.
有没有人知道我在XSLT转换过程中如何能够包含当前日期?
<a>
<xsl:attribute name="href">
<xsl:value-of select="/*/properties/property[@name='report']/@value" />
</xsl:attribute>
</a>
Run Code Online (Sandbox Code Playgroud)
是否有任何方法可以将另一个字符串添加到
<xsl:value-of select="/*/properties/property[@name='report']/@value" />
Run Code Online (Sandbox Code Playgroud)
除了报告属性值之外,我还需要将一些文本传递给href属性
如何在xsl:for-each循环中获取一个反映当前元素处理数量的计数器.
例如,我的源XML是
<books>
<book>
<title>The Unbearable Lightness of Being </title>
</book>
<book>
<title>Narcissus and Goldmund</title>
</book>
<book>
<title>Choke</title>
</book>
</books>
Run Code Online (Sandbox Code Playgroud)
我想得到的是:
<newBooks>
<newBook>
<countNo>1</countNo>
<title>The Unbearable Lightness of Being </title>
</newBook>
<newBook>
<countNo>2</countNo>
<title>Narcissus and Goldmund</title>
</newBook>
<newBook>
<countNo>3</countNo>
<title>Choke</title>
</newBook>
</newBooks>
Run Code Online (Sandbox Code Playgroud)
要修改的XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<newBooks>
<xsl:for-each select="books/book">
<newBook>
<countNo>???</countNo>
<title>
<xsl:value-of select="title"/>
</title>
</newBook>
</xsl:for-each>
</newBooks>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
所以问题是应该用什么代替?是否有任何标准关键字或我是否必须声明一个变量并在循环内增加它?
由于问题很长,我应该期待一行或一个单词的答案:)
我正在运行我的DOM的所有文本节点,并检查nodeValue是否包含某个字符串.
/html/body//text()[contains(.,'test')]
Run Code Online (Sandbox Code Playgroud)
这是区分大小写的.但是,我也想抓住Test,TEST奥得TesT.这可能与XPath(在JavaScript中)?
我知道有一些在线正则表达式评估器..非常有用,实时匹配.它们就像RegexBuddy的Web应用程序.
我想知道xPath选择器是否有类似的东西?我只是在学习它们,这对我来说很有价值.
是否有一个在线测试器,允许您输入XML,然后是xPath选择器和匹配(现场会更好,但我怀疑有人编写了JavaScript解释器吗?)吗?
谢谢
我是XSLT的新手,无法解决以下代码出错的问题.
<xsl:variable name="var" select="boolean('false')"/>
<xsl:if test="$var'">variable is true</xsl:if>
Run Code Online (Sandbox Code Playgroud)
当它意味着虚假时,它总是返回真实.为什么?
我正在研究xslt并开始测试w3schools上的示例.
但是,当我将xml和xsl保存在文件中并尝试在本地打开它们时,chrome将不会执行xsl转换.它只显示一个空白页面.
我已将<?xml-stylesheet type="text/xsl" href="style.xsl">标记添加到xml文档中,并且firefox将其呈现为应该看起来的样子.此外,如果我通过Web服务器查看文件,chrome会显示该文件应该看起来的样子.
当链接是本地链接时,chrome是否在查找样式表信息时遇到问题?将href更改为file:///C:/xsl/style.xsl没有任何区别.
更新:这似乎是安全策略的一个副作用,即不将file:///*视为同一来源.这会使控制台中出现以下错误:
不安全的尝试从URL文件加载URL文件:/// C:/xsl-rpg/style.xsl:/// C:/xsl-rpg/data.xml.域,协议和端口必须匹配.
我真的不知道XSL但是我需要修复这个代码,我已经减少了它以使它更简单.
我收到了这个错误
无效的XSLT/XPath函数
在这条线上
<xsl:variable name="text" select="replace($text,'a','b')"/>
Run Code Online (Sandbox Code Playgroud)
这是XSL
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:inm="http://www.inmagic.com/webpublisher/query" version="1.0">
<xsl:output method="text" encoding="UTF-8" />
<xsl:preserve-space elements="*" />
<xsl:template match="text()" />
<xsl:template match="mos">
<xsl:apply-templates />
<xsl:for-each select="mosObj">
'Notes or subject'
<xsl:call-template
name="rem-html">
<xsl:with-param name="text" select="SBS_ABSTRACT" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="rem-html">
<xsl:param name="text" />
<xsl:variable name="text" select="replace($text, 'a', 'b')" />
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
谁能告诉我它有什么问题?