xsl-list
[Top] [All Lists]

Re: building path expressions around dynamic element node names

2005-05-18 06:52:27


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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--