Subject: RE: [xsl] Value of the variable From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 27 Nov 2009 13:10:46 +0530 |
Interestingly, this question was asked about an hour ago on LinkedIn. The poster of that question gave an explicit input and an explicit output, so it was very easy to be able to answer.
t:\ftemp>type siddhi.xml <book>key1, k<i>e</i>y2, key<b>3</b>, <u>ke</u>y4, <b>k</b>ey<i>5</i></book>
<xsl:template match="book"> <!--preserve the book element and any of its attributes--> <xsl:copy> <xsl:copy-of select="@*"/>
<!--determine all of the portions that make up the line--> <xsl:variable name="portions" as="element(portion)*"> <xsl:apply-templates mode="make-portions"/> </xsl:variable>
<!--those portions ending with a comma make up the new results--> <xsl:for-each-group select="$portions" group-ending-with="*[@comma-end='true']"> <!--surround each group of portions--> <key> <xsl:copy-of select="current-group()/node()"/> </key> <xsl:if test="position()!=last()">, </xsl:if> </xsl:for-each-group> </xsl:copy> </xsl:template>
<!--make numerous portions from a given text node--> <xsl:template match="text()" mode="make-portions"> <xsl:for-each select="tokenize(.,',\s+')"> <portion comma-end="{position()!=last()}"> <xsl:value-of select="."/> </portion> </xsl:for-each> </xsl:template>
<!--make a single portion from a given element node--> <xsl:template match="*" mode="make-portions"> <portion><xsl:copy-of select="."/></portion> </xsl:template>
-- Vote for your XML training: http://www.CraneSoftwrights.com/s/i/ Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Value of the variable, G. Ken Holman | Thread | RE: [xsl] Value of the variable, Hermann Stamm-Wilbra |
RE: [xsl] Print vs Screen XSLT styl, Michael Kay | Date | RE: [xsl] Value of the variable, Hermann Stamm-Wilbra |
Month |