[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Cleaning text away from context position ...
Hi,
I'm toying with a stylesheet that copies an XML document .. and adds an attribute named id: For the root element, id is 1 For some other element, id is that of the parent, plus ',' plus the child cardinality of the element (so first child of the root is 1,1, second child of the root is 1,2, second child of third child of the root is 1,3,2 etc). Something like: <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="*|@*|comment()|processing-instruction()"> <xsl:param name="id" select="''"/> <xsl:param name="sep" select="''"/> <xsl:variable name="qid" select="concat($id, $sep, position())"/> <xsl:copy> <xsl:attribute name="id"> <xsl:value-of select="$qid"/> </xsl:attribute> <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"> <xsl:with-param name="id" select="$qid"/> <xsl:with-param name="sep" select="','"/> </xsl:apply-templates> </xsl:copy> </xsl:template> Applying it to itself, I get <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="1" version="1.0"> <xsl:template id="1,5" match="*|@*|comment()|processing-instruction()"> <xsl:param id="1,5,3" name="id" select="''"/> <xsl:param id="1,5,5" name="sep" select="''"/> <xsl:variable id="1,5,7" name="qid" select="concat($id, $sep, position())"/> <xsl:copy id="1,5,9"> <xsl:attribute id="1,5,9,2" name="id"> <xsl:value-of id="1,5,9,2,3" select="$qid"/> </xsl:attribute> <xsl:apply-templates id="1,5,9,4" select="*|@*|comment()|processing-instruction()|text()"> <xsl:with-param id="1,5,9,4,3" name="id" select="$qid"/> <xsl:with-param id="1,5,9,4,5" name="sep" select="','"/> </xsl:apply-templates> </xsl:copy> </xsl:template> </xsl:stylesheet> - not quite what I wanted, as text nodes are included in the context list and affect context positions. What to do about it? I want to preserve text nodes. Seems I can't select and recurse on all element nodes and all text nodes separately (getting a nice context list of elements only), as that would mess up the order of things. Any good ideas? Need to recurse in the sibling direction instead? Soren
|
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
|