|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Help with simple XSL
I have an XML document, which describes university style guides for web pages. The structure to the document looks like this.
<styleguide> <rule> <name>style guide rule</name> <description>Some content <link href=”some url”>content that is a hyperlink </link> more content</description> </rule> <rule> <name>another style guide rule</name> <description>Content <link href="some url">content that is a hyperlink </link> More content </description> </rule> </styleguide> My question is how can I retrieve the link information and transform it to a HTML hyperlink? Not all description tags have content that are links but some do. I have read a number of Xpath and XSLT tutorials because I am new to the XML world but I just can’t figure out how to deal with the link element if it exisists within a description element. Any help would be greatly appreciated. Thanks! |
|
#2
|
||||
|
||||
|
Try:
Code:
<xsl:if test="description/link">
<a href='{description/link/@href}'>
<xsl:value-of select="description/link/text()">
</a>
</xsl:if>
|
|
#3
|
|||
|
|||
|
Thanks for the reply. I guess I need to be a little more clear. If my description has a link element in the middle of the content I can get the first part of the content to display and the link element content, but I can't get the rest of the description content to display.
For example: <description>this is text in my description. <link url="some url">This text is a hyperlink</link> this is more text in my description.</description> After I run into a link element I can't get the rest of the content in my description tag to appear. Thanks again for the reply. Any help on this would be great. |
|
#4
|
||||
|
||||
|
apply this style sheet against your xml and see if it gives you a starting point. It will work for your xml data as long as it only has one <link> per description. You probably will be able to expand the scale with some time:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="styleguide/rule">
<xsl:value-of select="concat('Name: ', name)" />
<br />
<xsl:for-each select="description">
<xsl:value-of select="substring-before(., link)" />
</xsl:for-each>
<xsl:for-each select="description/link">
<a href="http://{@href}">
<xsl:value-of select="." />
</a>
</xsl:for-each>
<xsl:for-each select="description">
<xsl:value-of select="substring-after(., link)" />
</xsl:for-each>
<br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Let me know if it helps...
__________________
mr... mike.rusaw@realpage.com RalPage, Inc. "I have made this letter longer than usual, only because I have not had the time to make it shorter." - Blaise Paschal |
|
#5
|
|||
|
|||
|
I just ran the style sheet and it works great. I think this will be a good enough starting point for me to figure out how to deal with multiple links are zero links. Thanks for the help and the reply.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Help with simple XSL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|