Reputation: 1170
I have a XSL/XML parser to produce html code.
The xml is like this.
<root>
<a>
<url> http://image.jpg </url>
<x> 100 </x>
<y> 200 </y>
...
</a>
</root>
and the XST should be something like this. In style I want do define a background url using the value of xml node. How can I do it?
<xsl:template match="root">
<xsl:for-each select="a">
<div class="crop_image" style="background:url("<xsl:value-of select="url"/>") -<xsl:value-of select="x"/>px -<xsl:value-of select="y"/>px">"</div>
</xsl:for-each>
</xsl:template>
Thanks
Upvotes: 1
Views: 176
Reputation: 70598
What you are looking for are "Attribute Value Templates", which allow you to write values from your XML directly into attributes
<xsl:template match="root">
<xsl:for-each select="a">
<div class="crop_image" style="background:url({url}) -{x}px -{y}px">"</div>
</xsl:for-each>
</xsl:template>
The curly braces indicate an expression to be evaluated, rather than output literally, so {url}
for example will be replaced with http://image.jpg
in your output.
Upvotes: 2