XSLT:向列表中添加几个变量
XSLT: Add few Variables to List
我正在尝试使用 XSTL 将变量添加到来自 XML 的列表并创建合并标签,但它没有发生。
Source XML.
<Result>
<Data>
<Pass>true</Pass>
<Data>
<account>
<accountNumber>1111</accountNumber>
</account>
<account>
<accountNumber>2222</accountNumber>
</account>
</Result>
Requirement is that the output tag should have the list with Pass tag value like below.
<Student>
<accountNumber>1111</accountNumber>
<Pass>true</Pass>
<Student>
<Student>
<accountNumber>2222</accountNumber>
<Pass>true</Pass>
<Student>
当前的 XSLT 文件提供了列表,但我无法添加 Pass Tag。
<xsl:template match = "Root/Result">
<xsl:apply-templates select="account"/>
</xsl:template>
<xsl:template match = "account">
<Student>
<accountNumber><xsl:value-of select="accountNumber" /></accountNumber>
</Student>
</xsl:template>
试试这个:
<xsl:template match = "account">
<Student>
<accountNumber><xsl:value-of select="accountNumber" /></accountNumber>
<xsl:copy-of select="preceding-sibling::Pass"/>
</Student>
</xsl:template>
更新。由于源数据已更改,这就是您随后需要的:
<xsl:template match = "account">
<Student>
<accountNumber><xsl:value-of select="accountNumber" /></accountNumber>
<xsl:copy-of select="preceding-sibling::Data/Pass"/>
</Student>
</xsl:template>
我正在尝试使用 XSTL 将变量添加到来自 XML 的列表并创建合并标签,但它没有发生。
Source XML.
<Result>
<Data>
<Pass>true</Pass>
<Data>
<account>
<accountNumber>1111</accountNumber>
</account>
<account>
<accountNumber>2222</accountNumber>
</account>
</Result>
Requirement is that the output tag should have the list with Pass tag value like below.
<Student>
<accountNumber>1111</accountNumber>
<Pass>true</Pass>
<Student>
<Student>
<accountNumber>2222</accountNumber>
<Pass>true</Pass>
<Student>
当前的 XSLT 文件提供了列表,但我无法添加 Pass Tag。
<xsl:template match = "Root/Result">
<xsl:apply-templates select="account"/>
</xsl:template>
<xsl:template match = "account">
<Student>
<accountNumber><xsl:value-of select="accountNumber" /></accountNumber>
</Student>
</xsl:template>
试试这个:
<xsl:template match = "account">
<Student>
<accountNumber><xsl:value-of select="accountNumber" /></accountNumber>
<xsl:copy-of select="preceding-sibling::Pass"/>
</Student>
</xsl:template>
更新。由于源数据已更改,这就是您随后需要的:
<xsl:template match = "account">
<Student>
<accountNumber><xsl:value-of select="accountNumber" /></accountNumber>
<xsl:copy-of select="preceding-sibling::Data/Pass"/>
</Student>
</xsl:template>