Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xml-dev] XSTL stylesheet workarounds for exceptions

From: Jack Bush <netbeansfan@-----.---.-->
To: Michael Kay <mike@--------.--->, butlerdi@-----.---
Date: 2/4/2009 12:54:00 PM
Gentlemen,
 
Thank you for your suggestions and I finally worked out the reason why the 2 values fishing, rabbit were not been picked up after debugging. It turned out that there are two different types of Hobbie(s) elements which is shown as follows:
The only difference between the 2 matching pattern elements is the additional letter 's'. I used the following matching patterns to pick up all values for both elements:
 
<xsl:template match="ns:p[ns:strong='Hobbie:']|ns:p[ns:strong='Hobbies:']"> 
<xsl:for-each select="ns:a">
<hobbie><xsl:value-of select="."/></hobbie> 
</xsl:for-each> 
</xsl:template> 
Note that the matching name Hobbie is only an arbitray name that I used in position for the actual element name. As a result, it was not as obvious to distinguish between Hobby and Hobbies.
 
Now the only question left is the second half ( ii ) of the original post included below:
 <p> <strong>Hobbie:</strong> 
(Out-door adventures)<a shape="rect"href=http://www.hobbies.com/fishingtitle="Shark Hunting">fishing</a></p><p> <strong>Hobbies:</strong> <a shape="rect"href=http://www.hobbies.com/fishingtitle="Shark Hunting">fishing</a> 
(Out-door adventures)<a shape="rect"href=http://www.hobbies.com/huntingtitle="Animal">rabbit</a></p>( ii ) I also like to add a default generic value for any missing element. Say if there are no 
<p><strong>Hobbies:</strong></p> in such document, yet I still would like to generate a 
null element such as <hobbies>Unknown</hobbies>. The intended stylesheet should look 
like the following but couldn’t get it working still:
<xsl:template match="/">
<employee>
<xsl:apply-templates select="//ns:p"/>
</employee>
</xsl:template>
<xsl: choose>
<xsl: when test="ns:p[ns:strong='Hobbies:']">
<xsl:template match="ns:p[ns:strong='Hobbies:']"> 
<xsl:for-each select="text()[normalize-space() != '']"> 
<hobbies><xsl:value-of select="normalize-space()"/></hobbies> 
</xsl:for-each> 
</xsl:template></xsl:when>
<xsl:otherwise>
<hobbies>Unknown</hobbies> 
</xsl:otherwise>
</xsl: choose>
 However, this syntax does not conform with XSLT stylesheet.
Any suggestion would be much appreciated.
Thanks again,
Jack



________________________________
From: Michael Kay <mike@s...>
To: Jack Bush <netbeansfan@y...>; xml-dev@l...
Sent: Wednesday, 4 February, 2009 12:40:53 AM
Subject: RE: [xml-dev] XSTL stylesheet workarounds for exceptions


 
My next step would be to debug this stylesheet but any other suggestion would be more than welcome.
 
 
I rather assumed that you only posted to the list after failing to debug the stylesheet.
 
Your next step might be to post a complete but minimal source document and stylesheet that demonstrate the problem.
 
Michael Kay
http://www.saxonica.com/


      Make Yahoo!7 your homepage and win a trip to the Quiksilver Pro.. Find out more


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent