xslt 1.0 -在同一行中获得用逗号分隔的两个xml元素



我想要一个对xml文件进行操作的xslt文件,以便在一行中以逗号分隔两个prod-id和文章号。这只应该发生在某些地方产品没有项目

我的输入xml文件是:

<?xml version="1.0" encoding="UTF-8"?>
<products>
    <product>
        <prod-id>P16653</prod-id>
        <product-status>CREATED</product-status>
        <validation-status>Valid</validation-status>
        <duplication-status>Unique</duplication-status>
        <content-status>New</content-status>
        <article-number>233060</article-number>
        <languagedata>
            <language>
                <languageid>en-GB</languageid>
                <buying-description>FENDI L VELOUR SWEAT PANTS BEIGE</buying-description>
                <customer-long-description>FENDI L VELOUR SWEAT PANTS BEIGE</customer-long-description>
            </language>
        </languagedata>
        <items/>
        <created-on>2016-08-12T11:30:00</created-on>
        <created-by>Administrator</created-by>
        <last-changed-on>2016-08-04T17:34:00</last-changed-on>
        <last-changed-by>ap0712</last-changed-by>
        <delete>false</delete>
    </product>
    <product>
        <prod-id>P16659</prod-id>
        <product-status>CREATED</product-status>
        <validation-status>Valid</validation-status>
        <duplication-status>Unique</duplication-status>
        <content-status>New</content-status>
        <article-number>345940</article-number>
        <languagedata>
            <language>
                <languageid>en-GB</languageid>
                <buying-description>FENDI L VELOUR SWEAT PANTS BEIGE</buying-description>
                <customer-long-description>FENDI L VELOUR SWEAT PANTS BEIGE</customer-long-description>
            </language>
        </languagedata>
        <items/>
        <created-on>2016-08-12T11:30:00</created-on>
        <created-by>Administrator</created-by>
        <last-changed-on>2016-08-04T17:34:00</last-changed-on>
        <last-changed-by>ap0712</last-changed-by>
        <delete>false</delete>
    </product>
    <product>
        <prod-id>P16755</prod-id>
        <product-status>CREATED</product-status>
        <validation-status>Valid</validation-status>
        <duplication-status>Unique</duplication-status>
        <content-status>New</content-status>
        <article-number>11060</article-number>
        <languagedata>
            <language>
                <languageid>en-GB</languageid>
                <buying-description>FENDI L VELOUR SWEAT PANTS BEIGE</buying-description>
                <customer-long-description>FENDI L VELOUR SWEAT PANTS BEIGE</customer-long-description>
            </language>
        </languagedata>
        <items>
            <item>
                <item-id>i16754</item-id>
                <item-status>CREATED</item-status>
                <validation-status>Valid</validation-status>
                <duplication-status>Unique</duplication-status>
                <content-status>New</content-status>
            </item>
        </items>
        <created-on>2016-08-12T11:30:00</created-on>
        <created-by>Administrator</created-by>
        <last-changed-on>2016-08-04T17:34:00</last-changed-on>
        <last-changed-by>ap0712</last-changed-by>
        <delete>false</delete>
    </product>
    <product>
        <prod-id>P16633</prod-id>
        <product-status>CREATED</product-status>
        <validation-status>Valid</validation-status>
        <duplication-status>Unique</duplication-status>
        <content-status>New</content-status>
        <article-number>21069</article-number>
        <languagedata>
            <language>
                <languageid>en-GB</languageid>
                <buying-description>FENDI L VELOUR SWEAT PANTS BEIGE</buying-description>
                <customer-long-description>FENDI L VELOUR SWEAT PANTS BEIGE</customer-long-description>
            </language>
        </languagedata>
        <items/>
        <created-on>2016-08-12T11:30:00</created-on>
        <created-by>Administrator</created-by>
        <last-changed-on>2016-08-04T17:34:00</last-changed-on>
        <last-changed-by>ap0712</last-changed-by>
        <delete>false</delete>
    </product>
    <product>
        <prod-id>P16785</prod-id>
        <product-status>CREATED</product-status>
        <validation-status>Valid</validation-status>
        <duplication-status>Unique</duplication-status>
        <content-status>New</content-status>
        <article-number>9881061</article-number>
        <languagedata>
            <language>
                <languageid>en-GB</languageid>
                <buying-description>FENDI L VELOUR SWEAT PANTS BEIGE</buying-description>
                <customer-long-description>FENDI L VELOUR SWEAT PANTS BEIGE</customer-long-description>
            </language>
        </languagedata>
        <items>
            <item>
                <item-id>i16757</item-id>
                <item-status>CREATED</item-status>
                <validation-status>Valid</validation-status>
                <duplication-status>Unique</duplication-status>
                <content-status>New</content-status>
            </item>
        </items>
        <created-on>2016-08-12T11:30:00</created-on>
        <created-by>Administrator</created-by>
        <last-changed-on>2016-08-04T17:34:00</last-changed-on>
        <last-changed-by>ap0712</last-changed-by>
        <delete>false</delete>
    </product>
</products>

我希望输出为

P16653,233060
P16659,345940

我正在使用以下xslt,这是我从这个论坛得到的,并试图修改它,但它只给我文章编号,而不是两者

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="text"/>
    <xsl:template match="/">
        <xsl:value-of select="products/product[not(items/item)]/prod-id/concat(local-name(), ' ', .)" separator="&#10;"/>
        <xsl:value-of select="products/product[not(items/item)]/article-number/concat(local-name(), ' ', .)" separator="&#10;"/>
    </xsl:template>
</xsl:transform>

当我使用

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:output method="text"/>
    <xsl:template match="/">
        <xsl:value-of select="products/product[not(items/item)]/concat(prod-id, ',', article-number)" separator="&#10;"/>
    </xsl:template>
</xsl:stylesheet>

使用像Saxon 9这样的XSLT 2.0处理器得到

P16653,233060
P16659,345940
P16633,21069

你为什么不干脆:

<xsl:template match="/products">
    <xsl:for-each select="product[not(items/item)]">
        <xsl:value-of select="prod-id"/>
        <xsl:text>,</xsl:text>
        <xsl:value-of select="article-number"/>
        <xsl:text>&#10;</xsl:text>
    </xsl:for-each>
</xsl:template>

相关内容

  • 没有找到相关文章

最新更新