Forum Moderators: open

Message Too Old, No Replies

XSLT for-each

How to assign an incremental ID to HTML tag

         

tomda

10:44 am on Apr 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

I have a simple XSLT...

My XML is similar to this one (note the ID in the tag)


<vdms>
<vdm id="51833">
<text>My text</text>
</vdm>
<vdm id="75835">
<text>Another text</text>
</vdm>
<vdms>

Now, I just want to pick the ID and create another HTML tag with the same ID (so that I can use the getElementByID)

<xsl:for-each select="vdms/vdm">
<p id="<xsl:value-of select="@id" />"><xsl:value-of select="text" /></span></p>
</xsl:for-each>

But this doesn't work...

Any idea on what I should do to inset a value-of in the ID and get something like.

<p id="51833">My text</p>
<p id="75835">Another text</p>

Thanks

tomda

11:11 am on Apr 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I finally found the correct syntax... I spent my all morning searching for this, I guess it's because I am learning.

The solution is to use <xsl:attribute>
W3C >> [w3schools.com...]

And have something like this.

<xsl:for-each select="vdms/vdm">
<p><xsl:attribute name="id"><xsl:value-of select="@id" /></xsl:attribute></p>
</xsl:for-each>

Tomda

httpwebwitch

7:57 pm on Apr 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Learning XSLT is an uphill hike. We who are half way up that learning curve can relate to the burn you must feel in your programmer legs.

Keep with it - the payoff is worth the effort.

And get yourself a cool XSLT debugger like <oXygen/>, Stylus Studio, Visual Studio, XSLerator, or something like that. It'll make the climb easier.

tomda

6:09 am on Apr 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks httpwebwitch,

XSLT is fun ! And yes, I can feel the burn but time is flying :(

Thanks, I will check some of the app you mentioned but I only use open-source app (I am broke and not a pro) :) Will try some FF Addons first.

Thanks

cmarshall

2:56 am on Apr 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<oXygen/> is only $48 USD for the student edition. I recommend it highly. I couldn't imagine doing this with anything less.