[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: listing links in xsl?
"james walker" <jameswalkerandy@xxxxxxxxxxx> wrote in message news:Law9-F24bcsDFCa0fjh00027067@xxxxxxxxxxxxxx > given this xml structure (there are many links inside root): > <root> > <link> > <title>.......</title> > <url>....</url> > <description>.....s</description> > </link> > <root> > > i am trying to list the links on a web page by ndl links (links that contain > '.ndl') and then by html links. So far i have created a key: > xsl:key name="ndl-links" match="link" use="contains(url, '.ndl')=true" /> This is a bit confusing -- it is equivalent to the simpler: <xsl:key name="ndl-links" match="link" use="contains(url, '.ndl')" /> > which i though would assign a key to the links which contain '.ndl'? > > when i try and loop through the key it doesnt show the ndl links, however it > does show the html links? > > <xsl:template match="root"> > <ul> > > <xsl:for-each select="key('ndl-links', contains(url, '.ndl')=true)"> This will not return anything, because the current node "root" does not have "url" children. Here's a simple transformation that produces the output you want: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:key name="ndl-links" match="link" use="contains(url, '.ndl')" /> <xsl:template match="/"> Links with URL containing ".ndl": <xsl:copy-of select="key('ndl-links', true())"/> 
Links with URL not containing ".ndl": <xsl:copy-of select="key('ndl-links', false())"/> </xsl:template> </xsl:stylesheet> When applied on your source.xml (corrected to make it well-formed): <root> <link> <title>.......</title> <url>.ndl</url> <description>.....s</description> </link> <link> <title>.......</title> <url>.html</url> <description>.....s</description> </link> <link> <title>.......</title> <url>.ndl2</url> <description>.....s</description> </link> </root> the wanted result is produced: Links with URL containing ".ndl": <link> <title>.......</title> <url>.ndl</url> <description>.....s</description> </link><link> <title>.......</title> <url>.ndl2</url> <description>.....s</description> </link> Links with URL not containing ".ndl": <link> <title>.......</title> <url>.html</url> <description>.....s</description> </link> Hope this helped. Dimitre Novatchev. FXSL developer. http://fxsl.sourceforge.net/ -- the home of FXSL Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|