python and xslt problems

Mike Brown mike at skew.org
Sat Dec 28 18:02:03 EST 2002


> well my problem is with the example from
> http://uche.ogbuji.net:8080/uche.ogbuji.net/tech/akara/pyxml/ :
>
> #The identity transform: duplicates the input to output
> TRANSFORM = """<xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
> <xsl:template match="@*|node()">
>   <xsl:copy>
>     <xsl:apply-templates select="@*|node()"/>
>   </xsl:copy>
> </xsl:template>
> </xsl:stylesheet>
> """
> #And I don't even like Monty Python, folks
> SOURCE1 = """<spam id="eggs">What do you mean "bleah"</spam>"""
> SOURCE2 = """<spam id="eggs">I don't like spam</spam>"""
>
> from Ft.Xml.Xslt import Processor
> processor = Processor.Processor()
> from Ft.Xml import InputSource
> transform = InputSource.DefaultFactory.fromString(TRANSFORM,
> "http://spam.com/identity.xslt")
> processor.appendStylesheet(transform)
>
> #Now the processor is prepped with a transform and ccan be used
> #over and over for the same transform
> source = InputSource.DefaultFactory.fromString(SOURCE1,
> "http://spam.com/doc1.xml")
> result1 = processor.run(source)
> source = InputSource.DefaultFactory.fromString(SOURCE2,
> "http://spam.com/doc2.xml")
> result2 = processor.run(source)
> --------------------
> what does the second arg in InputSource.DefaultFactory.fromString do? as i
> understand the method it takes the first string arg and sets it as a
source
> for the following transformation.

The second argument is the URI you want to use to identify the document that
the InputSource is wrapping. Unless the document declares its own base URI
(via xml:base in XML, for example), the document's URI is used as the base
for resolving URI references that may be found within it. Any time you
process a document that may contain URI references, you need to inform the
processor what base to use.

URI references are URIs that may be relative (which in URI terms just means
no scheme), and that may have a fragment. They are found in XML in system
IDs (in the DOCTYPE declaration or in entity declarations within the DTD),
and in XSLT in places like xsl:include, xsl:import, and document().

If you fail to provide a document URI when constructing the InputSource, one
will be generated for you. However, it will be a UUID URN, which the default
resolver will not know how to use as a base URI.

> running on python 2.2.2 with installed Foursuite 0.12.0a2
> (and pyXML 0.8.1)

Don't use PyXML 0.8.1; it's buggier than 0.8.0 in some respects. To
eliminate your traceback, revert to PyXML 0.8.0 and try again. If it still
doesn't work, update 4Suite to 0.12.0a3, which was released on Oct 1.






More information about the Python-list mailing list