【发布时间】:2016-10-01 17:37:35
【问题描述】:
我有以下,源xml文件,xslt代码和输出xml
问题是我需要遍历节点 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>
【问题讨论】:
-
如果您 (a) 正确格式化代码并且 (b) 包含预期结果(作为代码),您的问题会更加清晰。将示例最小化为仅演示问题所必需的部分也是受欢迎的。
-
@michael.hor257k 我做了所有的事情来上传示例代码..但是格式化不起作用..代码上传本来是一个很好的功能