PDA

View Full Version : One more xml/xsl question.


enme
02.04.2002, 21:06
I'm working on a xml php blog type thing. Right now I'm working on the xml/xsl. I have attributes in my <enme:blog> tag which are left and top. They are used to set the left and top position of the blog obviously. But I can't figure out how to take the value of left and top in the xsl doc.

<xsl:template match="enme:blog">
<xsl:variable name="left" select="@left" />
<xsl:variable name="top" select="@top" />
<div style="left:left; top:top" class="enmeblog">
<xsl:apply-templates />
</div>
</xsl:template>

That's what I have now and it doesn't work at all. I tried it without those variables too and it didn't work either...

<xsl:template match="enme:blog">
<div style="left:@left; top:@top" class="enmeblog">
<xsl:apply-templates />
</div>
</xsl:template>

? How's that?

wranlon
03.04.2002, 01:50
One thing to keep in mind is that your expression can only exist in a few places, such as the select and test attribute values.

In your example below, you need to substitute the @left value for something that the XSL parser can use. @left won't work in any arbitrary location. Since breaking the div element apart would be heinously wrong (besides not working), you can use the xsl:attribute constructor.

For example:
<div>
<xsl:attribute name="style">
left:<xsl:value-of select="@left" />,
top:<xsl:value-of select="@top" />
</xsl:attribute>
</div>

You could use the variables here as well, except use $left and $top.

Stephen W. Cote
wranlon@hotmail.com
http://www.whitefrost.com/

enme
03.04.2002, 08:05
I don't know if you mistyped or not but you have a comma where there should be a semi-colan. Just letting you know in case you thought it should have been a comma. Thanks for the help!

wranlon
03.04.2002, 11:49
Sorry about that. Just a brain fart when I was writing it.

Stephen W. Cote
wranlon@hotmail.com
http://www.whitefrost.com/

Brian Nickel
03.04.2002, 17:47
<BLOCKQUOTE id=quote><font size=1 face="Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote><pre id=code><font face=courier size=2 id=code><xsl:template match="enme:blog">
<div style="left:@left; top:@top" class="enmeblog">
<xsl:apply-templates />
</div>
</xsl:template></font id=code></pre id=code><hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Arial, Helvetica" size=2 id=quote>
This method will work when browsers catch up with specs.

<font face='Courier New'><font color=brown>.Brian
It is best to remain silent and be thought a fool than to open your mouth and remove all doubt.</font id=brown></font id='Courier New'>

wranlon
03.04.2002, 18:12
Oops. I stand corrected.

The implementation I read in the spec was for an attribute value template, and required curly braces.

<pre id=code><font face=courier size=2 id=code>
{$image-dir}/{href}
</font id=code></pre id=code>

I'm therefore curious if Enme's original example is correct as-is, or if it would required the {}'s. Either way, I'll have to keep that in mind as it is much nicer than my example :)

Stephen W. Cote
wranlon@hotmail.com
http://www.whitefrost.com/