Skip to content Skip to sidebar Skip to footer

Embedding Tags In Xslt

I have this xslt which is working:

Solution 1:

The reason it errors out is because it's no longer valid XML.

To do what you're trying to do:

<xsl:whentest="title"><divid="{title}"><xsl:value-ofselect="title"/></div></xsl:when>

You can put any sort of selector inside of the {} tags, or even reference variables if you have something complex.

<xsl:variablename="some_complex_variable"><xsl:value-ofselect="title"/></xsl:variable><xsl:whentest="title"><divid="{$some_complex_variable}"><xsl:value-ofselect="title"/></div></xsl:when>

A 3rd, long-winded way of doing it is to dynamically attach the attribute with xsl:attribute:

<xsl:whentest="title"><div><xsl:attributename="id"select="title"/></div></xsl:when>

Solution 2:

For 2nd part try using this template:

<xsl:templatename="parse"><xsl:paramname="input"/><xsl:paramname="position"/><xsl:iftest="$position &lt;= string-length($input)"><xsl:choose><xsl:whentest="substring($input, $position, 1) = '_'"><xsl:value-ofselect="translate(substring($input, $position + 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/><xsl:call-templatename="parse"><xsl:with-paramname="input"select="$input"/><xsl:with-paramname="position"select="$position + 2"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:value-ofselect="substring($input, $position, 1)"/><xsl:call-templatename="parse"><xsl:with-paramname="input"select="$input"/><xsl:with-paramname="position"select="$position + 1"/></xsl:call-template></xsl:otherwise></xsl:choose></xsl:if></xsl:template>

Usage:

<xsl:call-template name="parse"><xsl:with-param name="input" select="'area_of_expertise'"/><xsl:with-param name="position" select="1"/></xsl:call-template>

Solution 3:

For the second part, converting from underscores to camel case, you may want to look at String Processing in the XSLT Standard Library. With str:subst() to split at underscores, str:to-camelcase() to change letter case suitably, and concat() to add the "Label" suffix, you should be set.

Solution 4:

For the 1st part you could use:

<xsl:whentest="area_of_expertise"><div><xsl:attributename="id"><xsl:value-ofselect="area_of_expertise"/></xsl:attribute><xsl:value-ofselect="area_of_expertise"/></div></xsl:when>

Solution 5:

It might be a silly answer, but it seems that you need this simple trace:

<xsl:whentest="area_of_expertise"><divid="areaOfExperiseLabel"><xsl:value-ofselect="area_of_expertise"/></div></xsl:when>

Otherwise, why are you intersted in <xsl:value-of select="area_of_expertise"/> for @id if you then need another string?

Post a Comment for "Embedding Tags In Xslt"