开发者

how to match all elements and print them in the original order

I have an xml file i'm receiving and i want to format it using xsl.But the requirement is to grab the elements and print them out in the order i recieve the xml file. Looking at the sample below the first special element has got an order element and then the next one doesn't have one and the third one has one. So i want the output exactly that way. Thanks i nAdvance

<main>
<submain>
<detail>
<specials>
<spec-qty>1</spec-qty>
<spec-desc>   Receivable </spec-desc>
</specials>
<order>
<text>Test</text>
</order>
<specials>
&l开发者_如何转开发t;spec-qty>-1</spec-qty>
<spec-desc>Receivable1 </spec-desc>
</specials>
<specials>
<spec-qty>-1</spec-qty>
<spec-desc>          Receivable2 </spec-desc>
</specials>
<order>
<text>Test2</text>
</order>
</detail>
</submain></main>

Output should be:

qty 1   Receivable order:Test qty -1   Receivable1 qty -1   Receivable2 order: Test2

Thanks and sorry for the previous uncompleted code


You can use this template:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <xsl:apply-templates select="//detail/*[self::specials or self::order]"/>
    </xsl:template>

    <xsl:template match="specials">

        <xsl:value-of select="concat('qty ', spec-qty, '&#xA0;')"/>
        <xsl:value-of select="spec-desc"/>
        <xsl:text>&#xA0;</xsl:text>
    </xsl:template>

    <xsl:template match="order">
        <xsl:value-of select="concat('order:', text, '&#xA0;')"/>
    </xsl:template>

</xsl:stylesheet>

Output:

qty 1    Receivable  order:Test qty -1 Receivable1  qty -1           Receivable2  order:Test2
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜