Project

Profile

Help

use of document('') in xslt using saxon

Added by Anonymous over 15 years ago

Legacy ID: #6888254 Legacy Poster: Andy Mansfield (shands99)

Hi, I have local static items in a legacy xsl in the form of: <map:CountryCodeMap name="GB">UK</map:CountryCodeMap> With xalan we were always able to look up the items with : document('')/*/map:CountryCodeMap[@name='GB'] With Saxon I cannot use document(''), it gives me a malformed url exception. FODC0005: java.net.MalformedURLException: no protocol: Has any one else come accross this problem ? Regards, Andy


Replies (6)

Please register to reply

RE: use of document('') in xslt using saxon - Added by Anonymous over 15 years ago

Legacy ID: #6888459 Legacy Poster: Michael Kay (mhkay)

document('') works fine provided the base URI of your stylesheet document is known. The most common reason for it not being known is that you used a StreamSource without calling setSystemId() to say where the input came from. '' is a relative URI, like all relative URIs it is only meaningful relative to a known base URI.

RE: use of document('') in xslt using saxon - Added by Anonymous over 15 years ago

Legacy ID: #6888559 Legacy Poster: Andy Mansfield (shands99)

Thanks for the reply, I am using a DOMSource object i.e. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new ByteArrayInputStream(importMessage.getMessageBody())); Source source = new DOMSource(doc); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(new StreamSource(xslStream)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); Result result = new StreamResult(bos); transformer.transform(source, result); Setting the systemid did not seem to make any difference?

RE: use of document('') in xslt using saxon - Added by Anonymous over 15 years ago

Legacy ID: #6888567 Legacy Poster: Michael Kay (mhkay)

Of course the other thing to mention is that this device is never needed with XSLT 2.0. It's much better to put the map in a global variable.

RE: use of document('') in xslt using saxon - Added by Anonymous over 15 years ago

Legacy ID: #6888651 Legacy Poster: Michael Kay (mhkay)

Its' the base URI of the stylesheet that's needed, not the input document. You're supplying the stylesheet as a StreamSource with no systemId, just as I suspected. By the way, using a DOMSource as the input to your transformation makes it go 4 to 10 times slower. Don't do it unless you have a very good reason.

RE: use of document('') in xslt using saxon - Added by Anonymous over 15 years ago

Legacy ID: #6888678 Legacy Poster: Andy Mansfield (shands99)

So along the lines of : <xsl:variable name="globalMaps"> <map:myMap name="test1">VALUE</map:myMap> </xsl:variable> <xsl:template name="testLookup"> <xsl:value-of select="$globalMaps/map:myMap" </xsl:template>

RE: use of document('') in xslt using saxon - Added by Anonymous over 15 years ago

Legacy ID: #6888909 Legacy Poster: Michael Kay (mhkay)

That's right.

    (1-6/6)

    Please register to reply