Jump to content

XSL variables in a css style declaration


asylum

Recommended Posts

This is a piece of code from my .xsl file and when I try to assign the attribute src directly to background-image it works but I can't put that xsl declaration in quotes which I need to do so I decided to use a variable...but it just doesn't work...at all.

<?xml version="1.0" encoding="ISO-8859-1" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/content"><xsl:variable name="source" select="bglayer/attribute::src"/><html><head><style type="text/css">#body {        background-image: url("{$source}");        position: relative;        width: <xsl:value-of select="bglayer/attribute::width"/>;        height: <xsl:value-of select="bglayer/attribute::height"/>;}.item {        margin: 5px;}</style></head><body> <div id="body">  <xsl:apply-templates/> </div></body></html></xsl:template>

Link to comment
Share on other sites

Wouldn't a simple

background-image: url("<xsl:value-of select="bglayer/attribute::src"/>");

do the trick? Parenthesis as far as I know are only used inside attribute values. CSS however is consireder plain text, so <xsl:value-of> is the way to go.Oh, and just a tip. Why don't you use the "@" instead of "attribute::"?

Link to comment
Share on other sites

Wouldn't a simple
background-image: url("<xsl:value-of select="bglayer/attribute::src"/>");

do the trick? Parenthesis as far as I know are only used inside attribute values. CSS however is consireder plain text, so <xsl:value-of> is the way to go.Oh, and just a tip. Why don't you use the "@" instead of "attribute::"?

Thanks for the help. And I used the attribute:: because I thought the two were different. I thought the @ gave you the element with that attribute and the attribute:: would give you the actual attribute.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...