user5770325
user5770325

Reputation:

Passing an XSLT variable in between <text> tag(i.e.opening and closing <text> tag) in SVG in an XSLT program

I've spent a couple of days trying to figure out how to solve this problem which I'm about to share with you all. Your help will be truly appreciated.

So, there's this XML code that calls the following XSLT code snippet which I'm working on.

<xsl:for-each select="roomname">
                        <xsl:variable name="rmnmstX" select="@startx" />
                        <xsl:variable name="rmnmstY" select="@starty" />
                        <xsl:variable name="rmnmenX" select="@endx" />
                        <xsl:variable name="rmnmenY" select="@endy" />
                        <xsl:variable name="rmnmname" select="@name" />


                            <text x="{$rmnmstX*$ts}" y="{$rmnmstY*$ts}" style="font-family: Verdana;
           font-size  : 5;
           stroke     : #0000ff;
           fill       : #0000ff;
           opacity    : 0.65">DC ROOM</text>

</xsl:for-each>

Here, in between the SVG text tag where I've included the text DC ROOM I wish to pass the value of the last variable rmnmname in place of DC ROOM. I tried doing this by writing {$rmnmname} in place of DC ROOM but when I tested the XML document which calls this XSLT code I see {$rmnmname} instead of the value of the name attribute that I've passed in the XML code. The section of the XML code I'm manipulating to test the output looks like this:

<roomname endx="5" endy="3" id="RM0002" startx="2" starty="2" name="DC ROOM 1"></roomname>

I hope I'm able to get this through to you guys.

Upvotes: 0

Views: 334

Answers (1)

har07
har07

Reputation: 89285

You can use xsl:value-of to output value of your XSL variable as a text node :

.....
0.65"><xsl:value-of select="$rmnmname"/></text>
.....

Or just get the value from the source XML variable if you don't plan to use the same value anywhere else :

.....
0.65"><xsl:value-of select="@name"/></text>
.....

Upvotes: 1

Related Questions