Embedding Tags In Xslt
Solution 1:
The reason it errors out is because it's no longer valid XML.
To do what you're trying to do:
<xsl:when test="title">
<div id="{title}">
<xsl:value-of select="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:variable name="some_complex_variable">
<xsl:value-of select="title"/>
</xsl:variable>
<xsl:when test="title">
<div id="{$some_complex_variable}">
<xsl:value-of select="title"/>
</div>
</xsl:when>
A 3rd, long-winded way of doing it is to dynamically attach the attribute with xsl:attribute:
<xsl:when test="title">
<div>
<xsl:attribute name="id" select="title"/>
</div>
</xsl:when>
Solution 2:
For 2nd part try using this template:
<xsl:template name="parse">
<xsl:param name="input"/>
<xsl:param name="position"/>
<xsl:if test="$position <= string-length($input)">
<xsl:choose>
<xsl:when test="substring($input, $position, 1) = '_'">
<xsl:value-of select="translate(substring($input, $position + 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
<xsl:call-template name="parse">
<xsl:with-param name="input" select="$input"/>
<xsl:with-param name="position" select="$position + 2"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($input, $position, 1)"/>
<xsl:call-template name="parse">
<xsl:with-param name="input" select="$input"/>
<xsl:with-param name="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:when test="area_of_expertise">
<div>
<xsl:attribute name="id">
<xsl:value-of select="area_of_expertise"/>
</xsl:attribute>
<xsl:value-of select="area_of_expertise"/>
</div>
</xsl:when>
Solution 5:
It might be a silly answer, but it seems that you need this simple trace:
<xsl:when test="area_of_expertise">
<div id="areaOfExperiseLabel">
<xsl:value-of select="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"