0

I'm new to XSLT and I'm trying to grab the content of an attribute I've just created.

I have some XML, like the following:

<subpara id="subpara">
    <title>I am some heavy title</title>
        <para id="para">Here is some dummy text for a dummy para.</para>
            <table id="t01" tocentry="1">
            ...

in XSLT, I do:

<xsl:template match="subpara/title">
    <div>
        <xsl:attribute name="class">
            <xsl:text>title</xsl:text>
            <xsl:call-template name="addChangeClasses"/>
        </xsl:attribute>

        <xsl:attribute name="data-numbering">
            <xsl:apply-templates select="parent::*" mode="numbering"/>
        </xsl:attribute>
        # HERE I'D LIKE TO HAVE THE CONTENT OF THE ATTRIBUTE I JUST CREATED
        <xsl:value-of select"@data-numbering"/>  

        <xsl:apply-templates/>
    </div>
</xsl:template>

My intent is to create that output:

<div class="title" data-numbering="1.1">1.1 - I am some heavy title</div>

So I'm creating an attribute data-numbering, but I'd like to display its content. Obviously, doing <xsl:value-of select="@data-numbering"/> is not the proper way.

Anyone can help me, please ? Thanks in advance ! :)

1 Answer 1

1

Without seeing what your Template returns I'm only taking a best guess here :

<xsl:variable name="d_numb">
  <xsl:apply-templates select="parent::*" mode="numbering"/>
</xsl:variable>

<xsl:attribute name="data-numbering" select="$d_numb"/>

<xsl:value-of select="$d_numb"/>

So store whatever value is returned by the template in a variable. Then use this variable to populate the attribute and output the value.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes @Sebastien! That works! I just used <xsl:attribute name='data-numbering'/> Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.