Reputation: 2290
I am rather new to XSLT and was wondering how I can modify the href attribute of a tag with a value acquired from an XML node.
In particular, my XML file goes like this
<root>
<privileges edit="1" del="1"></privileges>
<rooms>
<room>
<id>1</id>
<roomNr>101</roomNr>
<locked>0</locked>
<lockdownReason></lockdownReason>
</room>
</rooms>
</root>
and my XSL file goes like
<xsl:for-each select="root/rooms/room">
<div class="column toolbox">
<xsl:if test="$edit = 1">
<a href='admin.php?room=VALUE_OF_ID__OF_CURRENTLY_SELECTED_NODE'>this is a link</a>
<p>edit is true</p>
</xsl:if>
</div>
<div class="column">Room Nr.:<xsl:value-of select="roomNr"/></div>
</xsl:for-each>
the capital letters indicate what I try to accomplish. Someone please be kind enough to reply. Thanks
Upvotes: 2
Views: 762
Reputation: 42950
You're looking for xsl:attribute. I'm not really sure about how the reference to the current id
should look, but something like this should get you started:
<a>
<xsl:attribute name="href">admin.php?room=<xsl:value-of select="./id"/></xsl:attribute>
this is a link
</a>
Upvotes: 0
Reputation: 66806
For your XSLT, the easiest thing would be to use an Attribute Value Template (AVT) and select the value of <id>
, like this:
<a href='admin.php?room={id}'>this is a link</a>
Upvotes: 2