[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Split into numbered files: without side-effect? (X
At 11:31 AM 9/28/2007, I wrote:
You can also build keys that index to paths, parts of paths or quasi-paths, especially if you have functions (XSLT 2.0) that help make them for you. Along these lines, here's a utility stylesheet with a function to build XPaths to nodes. I'm sure it could be more elegant (m:step is crying out for templates :-), and await suggestions. <?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:m="http://www.mulberrytech.com/xslt/util" exclude-result-prefixes="m"> <!-- test with this: <xsl:template match="*"> <xsl:text>
</xsl:text> <xsl:value-of select="m:path(.)"/> <xsl:apply-templates/> </xsl:template> <xsl:template match="text()"/> --> <xsl:function name="m:path" as="xs:string?"> <xsl:param name="who" as="node()?"/> <xsl:if test="exists($who)"> <xsl:value-of select="concat(m:path($who/parent::*),m:step($who))"/> </xsl:if> </xsl:function> <xsl:function name="m:step" as="xs:string"> <xsl:param name="who" as="node()"/> <xsl:value-of separator="''"> <xsl:text>/</xsl:text> <xsl:choose> <xsl:when test="$who/self::element()"> <xsl:value-of select="name($who)"/> <xsl:if test="count($who/../element()[name() = name($who)]) gt 1"> <xsl:text>[</xsl:text> <xsl:value-of select="count($who/preceding-sibling::*[name() = name($who)]) + 1"/> <xsl:text>]</xsl:text> </xsl:if> </xsl:when> <xsl:when test="$who/self::attribute()"> <xsl:text>@</xsl:text> <xsl:value-of select="name($who)"/> </xsl:when> <xsl:when test="$who/self::comment()"> <xsl:text>comment()</xsl:text> <xsl:if test="count($who/../comment()) gt 1"> <xsl:text>[</xsl:text> <xsl:value-of select="count($who/preceding-sibling::comment()) + 1"/> <xsl:text>]</xsl:text> </xsl:if> </xsl:when> <xsl:when test="$who/self::processing-instruction()"> <xsl:text>processing-instruction()</xsl:text> <xsl:if test="count($who/../processing-instruction()) gt 1"> <xsl:text>[</xsl:text> <xsl:value-of select="count($who/preceding-sibling::processing-instruction()) + 1"/> <xsl:text>]</xsl:text> </xsl:if> </xsl:when> <xsl:when test="$who/self::text()"> <xsl:text>text()</xsl:text> <xsl:if test="count($who/../text()) gt 1"> <xsl:text>[</xsl:text> <xsl:value-of select="count($who/preceding-sibling::text()) + 1"/> <xsl:text>]</xsl:text> </xsl:if> </xsl:when> </xsl:choose> </xsl:value-of> </xsl:function> </xsl:stylesheet>
|
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
|