xsl-list
[Top] [All Lists]

Re: Coma delimited values in attribute

2005-09-17 02:16:14
If you can use 2.0 (or 1.0 + extensions) then I would do it in 2
stages - the first stage sorts out the markup into a better structure.
 The second stage is really simple then.

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:variable name="betterMarkup">
        <xsl:for-each select="//field">
                <field>
                        <xsl:for-each select="tokenize(@value, ',')">
                                <value><xsl:value-of select="."/></value>
                        </xsl:for-each>
                </field>
        </xsl:for-each>
</xsl:variable>

<xsl:template match="Fields">
        <table>
                <xsl:apply-templates select="$betterMarkup"/>
        </table>
</xsl:template>

<xsl:template match="field">
        <tr>
                <xsl:apply-templates/>
        </tr>
</xsl:template>

<xsl:template match="value">
        <td>
                <xsl:apply-templates/>
        </td>
</xsl:template>

</xsl:stylesheet>


Here the variable $betterMarkup reorganises the input into a better structure:

<field>
        <value>tarif1</value>
        <value>tarif2</value>
        <value>tarif3</value>
        <value>tarif4</value>
</field>
<field>
        <value>str</value>
        <value>cur</value>
        <value>str</value>
        <value>cur</value>
</field>
<field>
        <value>1</value>
        <value>1</value>
        <value>1</value>
        <value>1</value>
</field>
<field>
        <value>152</value>
        <value>100</value>
        <value>252</value>
        <value>203</value>
</field>

The second stage then does an apply-templates on that structure.

If you wanted to do this in 1.0 you will need the node-set extension,
and optionally the tokenize extension (you could do it recursively)

cheers
andrew

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>