Welcome to WebmasterWorld Guest from 54.211.17.91

Forum Moderators: httpwebwitch

Message Too Old, No Replies

Links, For Each, and xml

   
2:18 pm on May 18, 2009 (gmt 0)

5+ Year Member



I am new to xml and having trouble with the code below. The rest of my page works perfectly. I am trying to pull in an external link and an internal link and nothing shows. The internal link text is the NavName attribute and the external link text is the Link attribute.

Does anyone see what I am doing wrong?

Here's the xsl.
____________________
<p>
<xsl:for-each select="Page">
<choose>
<when>
<a href="@URL"><value-of select="@Link" /></a>
</when>
<otherwise>
<a href="@URL"><value-of select="@NavName" /></a>
</otherwise>
</choose>
</xsl:for-each>
</p>
Here's the xml
________________
<Page Name="LinkList" Link="Test" URL="http://www.google.com" />
<Page ID="x1092" Name="LinkList" Link="People & Communities" URL="x1092.xml?Preview=true&Site=&UserAgent=&IncludeAllPages=true&tfrm=4" Title="People & Communities" Abstract="People & Communities" NavName="People & Communities" CreationDate="20090513T14:32:00" Changed="20090513T18:33:10" CategoryIds="" Schema="SectionFront" />

1:25 am on May 19, 2009 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



1) you need to prepend all XSLT entities with the XSL namespace.

<xsl:choose>
<xsl:when>

2) invalid XSLT syntax:
<a href="@URL">

should be

<a>
<xsl:attribute name="href" value="@URL"/>
<value-of select="@NavName" />
</a>

3) <xsl:choose> and <xsl:when> requires a conditional statement (it's analogous to an "if" statement...

W3Schools has some wicked tutorials on XSLT.
[w3schools.com...]

1:30 pm on May 19, 2009 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



welcome to WebmasterWorld!

Take a moment to peruse the Terms of Service [webmasterworld.com], then introduce yourself [webmasterworld.com] to the community.