我期望在输出中看到 hello
,但没有得到它。
xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:if test="//target">
<xsl:value-of select="@field"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="callwithparms - Copy.xslt"?>
<xml>
<partOne>
<target field="hello"/>
</partOne>
<partTwo>
<number input="2" find="hello" />
<number input="2" find="world" />
</partTwo>
</xml>
最佳答案
改变
<xsl:value-of select="@field"/>
至
<xsl:value-of select="//target/@field"/>
(此时,根上下文节点上没有 @field
属性;if
语句不会更改上下文节点,因为您的原始代码似乎是期待。)
信用:感谢Daniel Haley用于更正原始答案,即上下文节点是根元素,它实际上是根。
关于xml - 为什么此 XSLT 转换后没有出现输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46199988/