Skip to content Skip to sidebar Skip to footer

Xsl For Xml: Inserting Specific Classes Using Xsl

I have another XSLT question which follows on from the question I asked last week. XSL for Xml to table transformation for two rows and many columns. The challenges is to insert di

Solution 1:

Use this XSLT:

<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:my="my"><xsl:outputmethod="xml"omit-xml-declaration="yes"indent="yes"/><xsl:keyname="k"match="page"use="@section"/><xsl:paramname="short-name"select="true()"/><!-- Change param to false()--><my:data><clubname="Arsenal">AFC</club><clubname="Chelsea">CFC</club><clubname="ManUnited">MUFC</club><clubname="ManCity">MCFC</club></my:data><xsl:templatematch="/root"><table><tr><xsl:apply-templatesselect="page[generate-id() = generate-id(key('k', @section))]"/></tr><tr><xsl:apply-templatesselect="page[generate-id() = generate-id(key('k', @section))]"mode="page"/></tr></table></xsl:template><xsl:templatematch="page"><xsl:variablename="class"><xsl:choose><xsl:whentest="$short-name"><xsl:value-ofselect="document('')/*/*/club[@name = current()/@section]"/></xsl:when><xsl:otherwise><xsl:value-ofselect="@section"/></xsl:otherwise></xsl:choose></xsl:variable><tdclass="{$class}"><xsl:value-ofselect="."/></td><td></td></xsl:template><xsl:templatematch="page"mode="page"><td><xsl:value-ofselect="@number"/></td><td><xsl:value-ofselect="key('k', @section)[last()]/@number"/></td></xsl:template></xsl:stylesheet>

Depending on parameter $short-name it renders your 1 desired XML or 2.

Post a Comment for "Xsl For Xml: Inserting Specific Classes Using Xsl"