[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: building path expressions around dynamic element n

Subject: Re: building path expressions around dynamic element node names
From: Rahil <qamar_rahil@xxxxxxxxxxx>
Date: Wed, 18 May 2005 14:52:27 +0100
mis aword 2005
David Carlisle wrote:


You lost me there.


As always, a six line input file and a required result would be good

David




Tried a six line input.xml and some snippets of the .xsl processing as well as the sample output.html
------------
Input xml file:


<Top>
 <First>
       <A><Class id="123">First</Class></A>
       <B> <Class id="897">Not Present</Class></B>
 </First>
 <Second>
       <A> <Class id="567">Second</Class></A>
       <B><Class id="908">Car</Class></B>
 </Second>
 <SecondAgain>
   <A><Class id="567">SecondAgain</Class></A>
       <B><Class id="908">Not Present</Class></B>
 </SecondAgain>
</Top>

Process xsl file:

<xsl:template....>
<xsl:variable name="notPresent" select="'Not Present'"/>
<xsl:for-each select="/*/*/B/Class[.=$notPresent]">
<xsl:variable name="clsName" select="..//preceding-sibling::A/Class/text()"/>
<xsl:choose>
<xsl:when test="matches($clsName,'(.)([A-Z])')"><!--only call the template if there is any word to split-->
<xsl:call-template name="splitTerm">
<xsl:with-param name="AName" select="$clsName"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<AWord>A Wrd: <xsl:value-of select="$clsName"/></AWord>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>


<xsl:template name="splitTerm">
<xsl:param name="AName"/>
<xsl:variable name="splitA" select="tokenize(replace($AName,'(.)([A-Z])','$1 $2'), ' ')"/>
<!-- if either token exists as a parent element elsewhere and has results in B node() then proceed to next.
E.g. tokens 'Second', 'Again' - 'Second' exists as <Second> in input file and has values in B/Class viz. 'Car' so proceed to next occurrence of 'Not Present'.
-->
</xsl:template>



Output file (HTML):


A Entries B Entries

First                    Not Present
Second               Car
SecondAgain       'Occurs as Second'

------------------------

Hope this is slightly clearer. Else please let me know. I dont want to land up writing 10 lines of code when it can be done in 1.

Thanks
Rahil

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.