[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSTL stylesheet workarounds for exceptions
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: < p><strong>Hobbie:</strong> <a shape="rect" href=http://www.hobbies.com/fishing title="Shark Hunting">fishing</a> (Out-door adventures) </ p>< p><strong>Hobbies:</strong> <a shape="rect" href=http://www.hobbies.com/fishing title="Shark Hunting">fishing</a> <a shape="rect" href=http://www.hobbies.com/hunting title="Animal">rabbit</a> (Out-door adventures) </ p>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:
( 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: XSTL stylesheet workarounds for exceptions
Make Yahoo!7 your homepage and win a trip to the Quiksilver Pro. http://au.rd.yahoo.com/homepage/mailtagline/*http://au.docs.yahoo.com/homepageset/?p1=other&p2=au&p3=tagline.
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] |
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
|