我是xslt新手,我想用它从下面的xml输入中写出一个平面文件。
我还需要在每个父段之后提供一个行提要。
所以这个:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:test xmlns:ns0="urn:mynamespace.com:test">
<Header>
<OderId>9876</OderId>
<CustomerNo>Cust123</CustomerNo>
<Item>
<Product>N1234565</Product>
<SubItem>
<DelDate>20220601</DelDate>
<Quantity>10</Quantity>
</SubItem>
<SubItem>
<DelDate>20220602</DelDate>
<Quantity>5</Quantity>
</SubItem>
</Item>
<Item>
<Product>N54321</Product>
<SubItem>
<DelDate>20220701</DelDate>
<Quantity>3</Quantity>
</SubItem>
<SubItem>
<DelDate>20220702</DelDate>
<Quantity>17</Quantity>
</SubItem>
</Item>
</Header>
</ns0:test>需要产生这样的结果:
9876Cust123
N1234565
2022060110
202206025
N54321
202207013
2022070217我将有更多的字段,但只需要写出每个父级内部的所有内容,而不希望指定每个字段。
谢谢理查德
发布于 2022-05-17 03:07:29
AFAICT,你想做的是:
XSLT2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:for-each select="//*[*/text()]">
<xsl:value-of select="*/text()"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>请注意,这需要支持XSLT2.0或更高版本的处理器。
在XSLT1.0中,您可以执行以下操作:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:for-each select="//*[*/text()]">
<xsl:for-each select="*/text()">
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>不确定这种混在一起的不相关数据的格式有什么好处。
https://stackoverflow.com/questions/72265399
复制相似问题