【发布时间】:2018-02-23 15:05:32
【问题描述】:
环境: XSLT 1.0
转换将获取partOne 部分中的每个元素,并使用partTwo 属性在partTwo 部分中查找@field 属性,然后输出@value 属性。
我正在使用for-each 循环,想知道apply-templates 是否可以工作?
xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="file.xslt"?>
<xml>
<partOne>
<target field="hello"/>
<target field="world"/>
</partOne>
<partTwo>
<number input="2" find="hello" value="valone" />
<number input="2" find="world" value="valtwo" />
<number input="2" find="hello" value="valthree" />
<number input="2" find="world" value="valfour" />
</partTwo>
</xml>
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:apply-templates />
</xsl:template>
<xsl:template match="/xml/partOne/target">
,<xsl:value-of select="@field"/>
<xsl:for-each select="/xml/partTwo/number[@find=current()/@field]">
,<xsl:value-of select="@value"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
输出:
,hello
,valone
,valthree
,world
,valtwo
,valfour
【问题讨论】: