我有以下的,源XML文件,XSLT代码和XML输出为什么xslt中的“for-each select”函数不打印元素名称和标签?
的问题是,我需要遍历节点的JLine 使用:
xsl:for-each select="JLine"
这是正确的输出,但与缺少标签。 我需要实现循环,因为我将使用if条件来处理节点并消除一些不需要的元素。
XML输入
<?xml version="1.0" encoding="UTF-8"?>
<JLine sequence="1">
<Amount currencyID="USD">-700.000</Amount>
<FunctionalAmount currencyID="USD">-700.000</FunctionalAmount>
<ReportingCurrencyAmount currencyID="USD">-700.000</ReportingCurrencyAmount>
<GLAccount>
<GLNominalAccount>S1010053</GLNominalAccount>
<AccountingChartReference>
<ID accountingEntity="T00">T00</ID>
</AccountingChartReference>
</GLAccount>
<DimensionCodes>
<DimensionCode sequence="1" listID="VAT">KTS08010</DimensionCode>
<DimensionCode sequence="2" listID="FILE">KF86155281</DimensionCode>
</DimensionCodes>
</JLine>
<JLine sequence="2">
<Amount currencyID="USD">-700.000</Amount>
<FunctionalAmount currencyID="USD">50.000</FunctionalAmount>
<ReportingCurrencyAmount currencyID="USD">400.000</ReportingCurrencyAmount>
<GLAccount>
<GLNominalAccount>S1010053</GLNominalAccount>
<AccountingChartReference>
<ID accountingEntity="T00">T00</ID>
</AccountingChartReference>
</GLAccount>
<DimensionCodes>
<DimensionCode sequence="1" listID="VAT">mKTS08010</DimensionCode>
<DimensionCode sequence="2" listID="FILE">eKF86155281</DimensionCode>
</DimensionCodes>
</JLine>
XLT代码
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:for-each select="JLine">
<xsl:variable name="var:v1" select="DimensionCodes/DimensionCode" />
<xsl:if test="$var:v1">
<xsl:apply-templates select="." />
</xsl:if>
</xsl:for-each>
XML输出结果
<?xml version="1.0" encoding="UTF-8"?>
<JLine sequence="1">
<Amount currencyID="USD">-700.000</Amount>
<FunctionalAmount currencyID="USD">-700.000</FunctionalAmount>
<ReportingCurrencyAmount currencyID="USD">-700.000</ReportingCurrencyAmount>
<GLAccount>
<GLNominalAccount>S1010053</GLNominalAccount>
<AccountingChartReference>
<ID accountingEntity="T00">T00</ID>
</AccountingChartReference>
</GLAccount>
<DimensionCodes>
<DimensionCode sequence="1" listID="VAT">KTS08010</DimensionCode>
<DimensionCode sequence="2" listID="FILE">KF86155281</DimensionCode>
</DimensionCodes>
</JLine>
你的问题会更加清晰,如果你(一)格式化你的代码正确和(b )包括预期结果(作为代码)。将示例最小化为仅显示问题所需的内容也是受欢迎的。 –
@ michael.hor257k我做了所有事情上传示例代码..但格式化不起作用。代码上传将是一个很好的功能 –