Subject: Re: [xsl] Building a bidirectional map of namespaces prefix to namespace from wsdl:definition From: Farrukh Najmi <farrukh@xxxxxxxxxxxxxxxxxxxxx> Date: Sat, 22 Mar 2008 10:51:02 -0400 |
Let's assume, we have some WSDL document to run the below stylesheet (I tested with one of the examples available at, http://www.w3.org/2001/03/14-annotated-WSDL-examples.html).
Below is a 1.0 stylesheet I could think of for this requirement:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" version="1.0">
<xsl:output method="text" />
<xsl:template match="/*"> <xsl:variable name="ns-map"> <xsl:for-each select="namespace::*[not(name() = 'xml')]"> <info> <prefix><xsl:value-of select="name()" /></prefix> <uri><xsl:value-of select="." /></uri> </info> </xsl:for-each> </xsl:variable>
<!-- lookup example --> <xsl:variable name="key1" select="'es'" /> <xsl:variable name="key2" select="'http://schemas.xmlsoap.org/wsdl/'" />
<xsl:value-of select="exslt:node-set($ns-map)/info[prefix = $key1]/uri" /><xsl:text>
</xsl:text> <xsl:value-of select="exslt:node-set($ns-map)/info[uri = $key2]/prefix" /> </xsl:template>
</xsl:stylesheet>
I store the 'map' in a xsl:variable (a result tree fragment).
Please note, that this uses the node-set extension function to access values from the 'map'.
This solution might look a bit complicated. But it might be necessary, if you want the map to be stored somewhere, before accessing it.
Here is a simpler code, which directly accesses the properties of namespace nodes: (in this case the namespace nodes for the element could be considered stored in a 'map')
<xsl:template match="/*"> <xsl:value-of select="namespace::*[name() = 'es']" /><xsl:text>
</xsl:text> <xsl:value-of select="name(namespace::*[. = 'http://schemas.xmlsoap.org/wsdl/'])" /> </xsl:template>
I have tested this with Xalan-J 2.7.1.
I hope that these examples would work with Xalan, bundled with JDK 5. But I would recommend to use the latest Xalan version to have better compliance and performance.
On Fri, Mar 21, 2008 at 8:47 PM, Farrukh Najmi
<farrukh@xxxxxxxxxxxxxxxxxxxxx> wrote:
Mukul Gandhi wrote: > On Fri, Mar 21, 2008 at 7:08 AM, Farrukh Najmi > <farrukh@xxxxxxxxxxxxxxxxxxxxx> wrote: > >> I need to process a WSDL document via XSLT and build two maps from the >> namespace declaration in the wsdl:definition element. >> >> * Key is the namespace prefix and value is the namespace >> * Key is the namespace and value is the prefix >> > > This should be easy to do in XSLT (in 2.0 surely).
Does xalan in JDK 5 support XSLT 2.0? I do not believe so. For this reason I would like an XSLT 1.0 based solution.
> When you say, > "build two maps", then what kind of data structure in the stylesheet > are you looking to store the maps?
Probably based on xslt:key ( <http://www.w3schools.com/xsl/el_key.asp>).
> Or probably, you can output two XML > documents (or perhaps, text files), which contain the maps. >
No I am looking for an in-memory solution that will be used within the same stylesheet.
> >> Does anyone have an example of doing that or something similar that they >> can share along with a snippet that shows how to do a >> lookup of a value based on key. >> > > When you say, "do a lookup of a value based on key", you need to > clarify what data structure stores the map. If the maps are stored in > external XML or text files, you can do a lookup based on normal XPath > expressions. >
No the maps have to be internal to style sheet. An examples is shown here under lookup table 1.6:
<http://www.ibm.com/developerworks/library/ws-trans/listing1.html>
> If you could clarify on these aspects, we could try to solve the > problem, or can give suitable pointers ... >
Hopefully my needs are clearer now?
-- Regards, Farrukh Najmi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Building a bidirectional , Mukul Gandhi | Thread | [xsl] xsl:sort on fn:collection() ?, Robert Koberg |
Re: [xsl] format decimal numbers is, Martin Honnen | Date | Re: [xsl] Unexpected behavior with , Farrukh Najmi |
Month |