Xslt 如何获取所有子代节点的信息
如何获取所有子代零件的信息 我希望将xml转换为csv。 我只是尝试一个通用的解决方案,如果兄弟姐妹使用“,”。如果没有兄弟姐妹,则使用“|”作为分隔符 例如,如果我的输入为Xslt 如何获取所有子代节点的信息,xslt,csv,file-conversion,Xslt,Csv,File Conversion,如何获取所有子代零件的信息 我希望将xml转换为csv。 我只是尝试一个通用的解决方案,如果兄弟姐妹使用“,”。如果没有兄弟姐妹,则使用“|”作为分隔符 例如,如果我的输入为 <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="Q2.xsl"?> <data> <ShoppingMalls> <Shop>
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="Q2.xsl"?>
<data>
<ShoppingMalls>
<Shop>
<ShopNumber>1</ShopNumber>
<LineNumber>1</LineNumber>
<Address>
<Street> East </Street>
<PinCode>1 </PinCode>
</Address>
</Shop>
<Shop>
<ShopNumber>2</ShopNumber>
<LineNumber>2</LineNumber>
<Address>
<Street> West </Street>
<PinCode>1 </PinCode>
</Address>
</Shop>
</ShoppingMalls>
<Inventory>
<Line>
<LineNumber>line</LineNumber>
<Description>desc</Description>
<Matrix>quan</Matrix>
<Matrix>quan1</Matrix> <!-- added -->
<Date>date</Date>
</Line>
<Line>
<LineNumber>1</LineNumber>
<Description>Oak chairs</Description>
<Matrix>5</Matrix>
<Matrix>20</Matrix> <!-- added -->
<Matrix>16</Matrix> <!-- added -->
<Date>31 Dec 2004</Date>
</Line>
<Line>
<LineNumber>2</LineNumber>
<Description>Dining tables</Description>
<Matrix>
<Module1>
<Module11> 234</Module11>
<Module11> 333</Module11> <!-- could be nested till any level i.e. might have any number of descendants-->
</Module1>
<SubComp>300</SubComp>
<SubComp>500</SubComp>
<SubComp>800</SubComp>
</Matrix>
<Date>31 Dec 2004</Date>
</Line>
<Line>
<LineNumber>3</LineNumber>
<Description>Folding chairs</Description>
<Matrix>4</Matrix>
<Date>29 Dec 2004</Date>
</Line>
<Line>
<LineNumber>4</LineNumber>
<Description>Couch</Description>
<Matrix>1</Matrix>
<Date>31 Dec 2004</Date>
</Line>
</Inventory>
</data>
我想导航节点直到任何深度。
如果有同名的属性,那么我希望使用“,”(同级或多值attrinbutes)连接
对于其他节点,分隔符应为
属性与属性之间的“|”
换行符作为行节点之间的分隔符。
我使用了以前的解决方案。
我希望使用XSLT1.0
我寻求您帮助的解决方案
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" encoding="ISO-8859-1" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template name="Newline"><xsl:text>
</xsl:text></xsl:template>
<xsl:template match="/data/Inventory">
<xsl:text>ShoppingMalls Information</xsl:text>
<xsl:call-template name="Newline" />
<xsl:apply-templates select="Line"/>
</xsl:template>
<xsl:template match="data/ShoppingMalls">
<xsl:text>ShoppingMalls Information</xsl:text>
<xsl:call-template name="Newline" />
<xsl:apply-templates select="Shop"/>
</xsl:template>
<!-- the same solution for Inventory/Line can be used for ShoppingMalls/Shop
-->
<xsl:template match="Line">
<xsl:for-each select="*"> <!-- somehow I belive the ndes can be identfied over here -->
<!--
I THINK THIS BLOCK WILL HAVE SOLUTION
BEGIN
<xsl:if test="count(./child::*) > 1">
<xsl:when test="name(./child/following-sibling::*)=name(./child::*)" >
<xsl:text>,</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:if test="position() != last()">
<xsl:text>|</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:if>
END
-->
<xsl:choose>
<!-- below blocks gives a simple way to identify siblings, but it not extensible -->
<xsl:when test="name(./following-sibling::*)=name(.)" >
<xsl:text>,</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:if test="position() != last()">
<xsl:value-of select="'|'"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
购物中心信息
购物中心信息
,
;
何时开始发布格式良好的XML?请编辑并更正。更正完成。更正了输入xml。还更新了的xsl.mable副本
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" encoding="ISO-8859-1" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template name="Newline"><xsl:text>
</xsl:text></xsl:template>
<xsl:template match="/data/Inventory">
<xsl:text>ShoppingMalls Information</xsl:text>
<xsl:call-template name="Newline" />
<xsl:apply-templates select="Line"/>
</xsl:template>
<xsl:template match="data/ShoppingMalls">
<xsl:text>ShoppingMalls Information</xsl:text>
<xsl:call-template name="Newline" />
<xsl:apply-templates select="Shop"/>
</xsl:template>
<!-- the same solution for Inventory/Line can be used for ShoppingMalls/Shop
-->
<xsl:template match="Line">
<xsl:for-each select="*"> <!-- somehow I belive the ndes can be identfied over here -->
<!--
I THINK THIS BLOCK WILL HAVE SOLUTION
BEGIN
<xsl:if test="count(./child::*) > 1">
<xsl:when test="name(./child/following-sibling::*)=name(./child::*)" >
<xsl:text>,</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:if test="position() != last()">
<xsl:text>|</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:if>
END
-->
<xsl:choose>
<!-- below blocks gives a simple way to identify siblings, but it not extensible -->
<xsl:when test="name(./following-sibling::*)=name(.)" >
<xsl:text>,</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:if test="position() != last()">
<xsl:value-of select="'|'"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>