英文:
XSLT variable not recognized
问题
我以前使用过XSLT变量,但出现了一个问题,我无法让样式表看到分配的变量。当我复制示例代码时,它似乎可以工作,所以肯定是我做错了什么。以下是代码。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/JDF">
<xsl:variable name="customer"
select="/JDF/ResourcePool[1]/CustomerInfo[1]/@CustomerID"/>
<job>
<jobInfo>{$customer}</jobInfo>
</job>
</xsl:template>
</xsl:stylesheet>
当我运行上面的代码时,结果如下。
<?xml version="1.0" encoding="UTF-8"?>
<job>
<jobInfo>[此处是您的变量值]</jobInfo>
</job>
在<jobInfo>
元素中,您应该看到$customer
变量的值,而不是字符串"$customer"
。
英文:
I've worked with XSLT variables before, but for some reason, I can not get the stylesheet to see an assigned variable. When I copy sample code it seems to work, so it has to be something I'm doing wrong. Below is the code.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/JDF">
<xsl:variable name="customer"
select="/JDF/ResourcePool[1]/CustomerInfo[1]/@CustomerID"/>
<job>
<jobInfo>$customer</jobInfo>
</job>
</xsl:template>
</xsl:stylesheet>
When I run the above the result is this.
<?xml version="1.0" encoding="UTF-8"?>
<job>
<jobInfo>$customer</jobInfo>
</job>
答案1
得分: 4
XSLT 1.0, 2.0
Change
<jobInfo>$customer</jobInfo>
to
<jobInfo>
<xsl:value-of select="$customer"/>
</jobInfo>
XSLT 3.0+
If text value templates are enabled (using, for example xsl:stylesheet/@expand-text="yes"
), then you could use:
<jobInfo>{$customer}</jobInfo>
英文:
XSLT 1.0, 2.0
Change
<jobInfo>$customer</jobInfo>
to
<jobInfo>
<xsl:value-of select="$customer"/>
</jobInfo>
XSLT 3.0+
If text value templates are enabled (using, for example xsl:stylesheet/@expand-text="yes"
), then you could use:
<jobInfo>{$customer}</jobInfo>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论