我是 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
我將擁有比這更多的欄位,但只需要寫出每個父級中的所有內容,并且不想指定每個欄位。
謝謝理查德
uj5u.com熱心網友回復:
AFAICT,你想做:
XSLT 2.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>
請注意,這需要支持 XSLT 2.0 或更高版本的處理器。
在XSLT 1.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://www.uj5u.com/caozuo/478395.html
上一篇:將XmlArrayItemAttribute反序列化為PascalCase屬性為Null
下一篇:提取“<>”標簽內的文本
