[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: building path expressions around dynamic element n
David Carlisle wrote:
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
|
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
|