somejkuser
somejkuser

Reputation: 9040

Simple nested XSLT solutions

Here is my XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <clubs>
        <club>
            <buttons>
                <button>
                    <name>rating</name>
                    <generalclassname>rating</generalclassname>
                    <numericclassname>score</numericclassname>
                    <valuedata>1</valuedata>
                    <locid>1</locid>
                    <type>numcomments</type>
                    <label>Comments</label>
                    <icon>data:image/gif;base64,R0lGODlhDQAMAMQAAP////z8/Pn5+fX19e3t7evr6+np6eTk5ODg4N7e3tnZ2dfX18zMzMrKysPDw729vaurq6ampqKioqCgoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAADQAMAAAFQyAgjs1omsmUnGYATVDAAgIz3YwwLs97/7DHghABGiMEQKFonEQKI0NzYjAJproRYZocISYSx8EhmSBMCsZgNGAoRCEAOw==</icon>
                </button>
                <button>
                    <name>reviews</name>
                    <generalclassname>reviews</generalclassname>
                    <numericclassname>numreviews</numericclassname>
                    <valuedata>9</valuedata>
                    <locid>9</locid>
                    <type>numcomments</type>
                    <label>Comments</label>
                   <icon>data:image/gif;base64,R0lGODlhCwALAMQAAP////7+/v39/fr6+vn5+ff39/Dw8O7u7ufn5+Xl5eDg4Nvb29fX19bW1tDQ0MrKysbGxsTExMHBwcDAwLu7u7m5ubi4uLW1tbOzs7GxsbCwsK2traysrKurqwAAAAAAACwAAAAACwALAAAFOSAgjoEUjSjAdFcqKltXpQXU3YroPEh23xpKghNZ/Y6dIvKGSRqRDueyc5gokRaAgDAwLCC+TgMQAgA7</icon>
                </button>
                <button>
                    <name>comments</name>
                    <generalclassname>comments</generalclassname>
                    <numericclassname>numcomments</numericclassname>
                    <valuedata>8626</valuedata>
                    <locid>8626</locid>
                    <type>numcomments</type>
                    <label>Comments</label>
                    <icon>data:image/gif;base64,R0lGODlhCwALAKIAAP////7+/vX19c/Pz8LCwrCwsKCgoAAAACwAAAAACwALAAADHShT1l1DudkWnezqnTXcRmRhEWA2RGCuZ8qy7psAADs=</icon>
                </button>
            </buttons>
        </club>
    </clubs>

Here is my XSLT:

    <xsl:for-each select="./clubs/club">
    <xsl:for-each select="./buttons/button">
    <div style="bottom:50px">
    <xsl:attribute name="class" ><xsl:value-of select="/.generalclassname"/></xsl:attribute>
    <div>
    <xsl:attribute name="class"><xsl:value-of select="/.numericclassname"/></xsl:attribute>
    <xsl:value-of select="/.valuedata"/>
    </div><span><xsl:valueof select="./label"/></span>
    </div>
    </xsl:for-each>
    </xsl:for-each>

I don't think Im querying and coding this properly.

My resulting html should be:

<div class="comments"><div class="numcomments">1</div><span>Comments</span></div>

This is against the third record in the array.

Any help would be great.

Upvotes: 0

Views: 40

Answers (2)

KFayal
KFayal

Reputation: 44

Try this:

<xsl:output method="html" encoding="UTF-8" indent="yes"/>
<xsl:template match="button">
<div style="bottom:50px">
    <xsl:attribute name="class"><xsl:value-of select="generalclassname"/></xsl:attribute>
    <div>
    <xsl:attribute name="class"><xsl:value-of select="numericclassname"/></xsl:attribute>
            <xsl:value-of select="valuedata"/>
    </div>
    <span>
        <xsl:value-of select="label"/> 
    </span>
</div>
</xsl:template>

Upvotes: 0

Martin Honnen
Martin Honnen

Reputation: 167581

Change expressions like select="/.generalclassname" to select="generalclassname". I would however suggest to simplify the code using attribute value templates: <div class="{generalclassname}">.

Upvotes: 1

Related Questions