|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xsl:value-of select : how to make some tags printe
Mukul,
Since David is probably working and since I already stuck my nose in, I'll do so again. (He will of course correct me where I go wrong.) At 11:10 AM 10/7/2003, you wrote: Hi Judith, Taking hint from David Carlisle's answer, I have written this XSL -- This template reaches down from the root and directly selects all <text> element descendants. Any intermediate node structures (any wrapper elements the <text> elements appear inside of) will not be processed. Apart from a different priority (0.5 instead of 0, due to the match pattern), this is the same as <xsl:template match="text">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>which is, in effect, the identity template. (Except any attributes on the <text> element will be skipped.) This is what David suggested, but not what he meant to suggest. It copies the string value of the <sw> element to the result. Note any subordinate elements inside the <sw> will not be processed. (Not what the OP wanted.) This matches the <sub> in the source, and creates a <sub> in the output, but: 1. Any element nodes inside the <sub> (such as <i> or whatever) will not be processed: the value-of simply copies a string. 2. This template will never get hit in any case, since the rest of the stylesheet provides no way a <sub> element will ever be selected and matched. The solution David thought he was suggesting is: <xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template><xsl:template match="sw"> <xsl:apply-templates/> </xsl:template> which works as follows: 1. The first template, with a priority of -0.5, matches any node, copying it to the result, and processing its attributes and children, placing their results inside the copied node. 2. The second template, with a priority of 0 (beating out the first template), matches any <sw> node. It does not create any output, but it does process the child nodes of <sw>, ensuring they get processed. So <sub> elements inside will be matched by the first template, and copied. (So will their children and descendants.) For the benefit of those just learning XPath (and XSLT pattern-matching rules), the above is the same as: <xsl:template match="attribute::*|child::node()" priority="-0.5">
<!-- known in XSLT-speak as the "identity template" since it creates a
node-for-node copy of the input tree -->
<xsl:copy>
<xsl:apply-templates select="attribute::*|child::node("/>
</xsl:copy>
</xsl:template><xsl:template match="sw" priority="0"> <xsl:apply-templates select="child::node()"/> </xsl:template> I hope this clarifies -- Cheers, Wendell
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|

Cart








