I figured I would give it a go, and created a function that will return a Nodset with the different parts of the path attribute. The stylesheet down below is using it. It will iterate over all resources with a path attribute, and then for each resource apply the wadl-utils:parse() function to its @path attribute. This function will return a new document, and since it is an XML document, we can apply an XPath expression on it. In this case, the XPath expression is /path/*. So, inside of the for-each loop visiting all resources, there is another for-each loop visiting all parts of the @path attribute.
Looking back, it's questionable if something like this couldn't have been done using plain old XSLT, but it was an interesting excercise anyway. The code is in the WADL repository at http://wadl.dev.java.net/.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:wadl-utils="xalan://org.jvnet.ws.wadl.xslt.WadlXsltUtils"
xmlns:wadl="http://wadl.dev.java.net/2009/02"
exclude-result-prefixes="wadl-utils">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="//wadl:resource[@path]">
<xsl:value-of select="@path"/>
<xsl:text>: </xsl:text>
<xsl:for-each select="wadl-utils:parse(@path)/path/*">
<xsl:text>[</xsl:text>
<xsl:value-of select="local-name(.)"/>
<xsl:text>: '</xsl:text>
<xsl:value-of select="text()"/>
<xsl:text>']</xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
0 comments:
Post a Comment