Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > xslt syntax question

xslt syntax question
Thread Tools
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status: Offline
Reply With Quote
Sep 14, 2004, 05:19 AM
 
This has been taking too long for what is probably dead simple.....

Code:
<xsl:for-each select="bla/*"> <tr> <td><xsl:value-of select="field[@lang='en']"/></td> </tr> </xsl:for-each>
This is returning data where the 'lang' attribute is 'en'. i.e. <field lang="en">

What I would like is to also get data if no 'lang' attribute has been set. i.e. <field>
     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Sep 14, 2004, 11:10 AM
 
There are a bunch of ways of doing it... try this:
Code:
[not(@lang)]
and in case you were looking to catch both cases at once:
Code:
field[@lang='en']|field[not(@lang)]
I have not used this in a select statement, but in if clauses....
     
skalie  (op)
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status: Offline
Reply With Quote
Sep 15, 2004, 01:57 AM
 
That worked a treat, Larkost, and you also added intuitively the extra code which I was needing. That was to get default data when no language had been set, thanks a lot.

Had been Googling for an hour for that or so without success, either my Google skills have started to fade or there is little documentation out there of XSL syntax, maybe time to buy a book.

Next problem, however. How do I add a hyperlink?

If I place...
Code:
<a href='<xsl:value-of select="url"/>'><xsl:value-of select="link"/></a>
in the xsl file it throws an error, and if I use this syntax in the xml file...

Code:
&#60;a href="http://www.blabla.com"&#62;Bla Bla&#60;/a&#62;
....I get the result of <a href="www.blabla.com>Bla Bla</a>

     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Sep 15, 2004, 11:07 AM
 
Code:
<a> <xsl:attribute name="href"> <xsl:value-of select="link" /> </xsl:attribute> </a>
And you might want to check out the xslt tutoial over at w3schools to get the basics all filled in.
     
skalie  (op)
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status: Offline
Reply With Quote
Sep 15, 2004, 11:43 AM
 
I was going through that very same tutorial, although I must have missed some essentials when branching off to the xpath section and the suchlike.

Will perservere and thanks very much for the coding help, again.

From a beginners point of view it has to be said that xml, while simple in concept, gets rather complicated rather quickly.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:14 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2