...">

Embed tags in xslt

I have this xslt that works:

<xsl:when test="area_of_expertise">

    <div>
        <xsl:value-of select="area_of_expertise"/>
    </div>
</xsl:when>

but what I need matches the lines:

<xsl:when test="area_of_expertise">

    <div id="<xsl:value-of select="area_of_expertise"/>">
        <xsl:value-of select="area_of_expertise"/>
    </div>
</xsl:when>

However, in the second example there are errors .. does anyone know why?

Btw Is there a way to convert the name of a node area_of_expertiseto areaOfExperiseLabeland insert this as id? The conclusion I really need is:

<div id="areaOfExpertiseLabel">
    asasdasdasd
</div>
+3
source share
5 answers

For the second part, try using this template:

<xsl:template name="parse">
        <xsl:param name="input"/>
        <xsl:param name="position"/>


        <xsl:if test="$position &lt;= 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>

Using:

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

The reason it is mistaken is because it is no longer valid XML.

To do what you are trying to do:

<xsl:when test="title">

    <div id="{title}">
        <xsl:value-of select="title"/>
    </div>
</xsl:when>

You can put any type of selector inside {} tags or even reference variables if you have something complicated.

<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>

, - xsl:

<xsl:when test="title">

    <div>
        <xsl:attribute name="id" select="title"/>
    </div>
</xsl:when>
+3

, , String Processing XSLT. str:subst(), , str:to-camelcase(), , concat(), "", .

+1

1- :

<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>
+1

, , :

<xsl:when test="area_of_expertise">
    <div id="areaOfExperiseLabel">
        <xsl:value-of select="area_of_expertise"/>
    </div>
</xsl:when>

, <xsl:value-of select="area_of_expertise"/> @id, ?

0

All Articles