0

Trying to reference namespace to the same xslt with document('') but I get :

 SystemID: file:/c:/intersystems/cache/mgr/samples/; Line#: 1; Column#: 1
net.sf.saxon.trans.XPathException: Error reported by XML parser

....

Caused by: org.xml.sax.SAXParseException; systemId: file:/c:/intersystems/cache/mgr/samples/; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

So it seems can not reference the same xslt? Is there some way to do this

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fo="http://www.w3.org/1999/XSL/Format" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:fn="http://www.w3.org/2005/xpath-functions" 
xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:csv="csv:csv">
<!-- <xsl:output method="text" version="4.0" encoding="iso-8859-1" indent="yes"/> -->
<xsl:strip-space elements="*" />
<xsl:output method="text" encoding="utf-8" />
<xsl:variable name="delimiter" select="','"/>

<csv:columns>
<column>GlobalID</column>
<column>ServicePointName</column>
</csv:columns>

  <xsl:template match="/Report">
        <!-- Output the CSV header -->
          ****<xsl:for-each select="document('')/*/csv:columns/*">****
                <xsl:value-of select="."/>
                <xsl:if test="position() != last()">
                    <xsl:value-of select="$delimiter"/>
                </xsl:if>
        </xsl:for-each> 
        <xsl:text>&#xa;</xsl:text>

        <!-- Output rows for each matched Report -->
        <xsl:apply-templates select="*" />
    </xsl:template>

    <xsl:template match="/Report/CLI">
            <xsl:for-each select="//CLI">
                        <xsl:value-of select="GlobalID"/>
                        <xsl:value-of select="$delimiter"/>
                        <xsl:value-of select="ServicePointName"/>
                        <!-- Add a newline at the end of the record -->
                        <xsl:text>&#xa;</xsl:text>
             </xsl:for-each>


     </xsl:template>
</xsl:stylesheet>
  • 1
    What processor are you using? I can't reproduce this with Saxon 6.5.5 or Xalan (if I remove the `thisdoc` variable). – Daniel Haley Nov 26 '14 at 17:20
  • Take a look at this question too: http://stackoverflow.com/questions/4814116/xslt-document-function-doesnt-work – Daniel Haley Nov 26 '14 at 17:29
  • It seems that it is using: SAX XML validating parser using the standard Xerces library. – Thomas Kotze Nov 26 '14 at 19:38
  • The question is about your XSLT processor - see here how to get it: http://stackoverflow.com/questions/25244370/how-can-we-check-that-which-xslt-processor-uses-as-default-in-solr/25245033#25245033 – michael.hor257k Nov 26 '14 at 20:00
  • Ok, I just got that from the DB docs: The processor is: SAXON 9.1.0.8 from Saxonica2.0 – Thomas Kotze Nov 26 '14 at 21:05

2 Answers2

0

Saxon 9 is an XSLT 2.0 processor - so you can easily do:

XSLT 2.0

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>

<xsl:variable name="delimiter" select="','"/>

<xsl:variable name="columns">
    <column>GlobalID</column>
    <column>ServicePointName</column>
</xsl:variable>

<xsl:template match="/">
    <xsl:for-each select="$columns/*">
        <xsl:value-of select="."/>
        <xsl:if test="position() != last()">
            <xsl:value-of select="$delimiter"/>
        </xsl:if>
    </xsl:for-each> 
    <xsl:text>&#xa;</xsl:text>

    <!-- the rest -->

</xsl:template>

</xsl:stylesheet>

I don't see that you're using the columns further on in your stylesheet. If so, why don't you simplify the whole thing to:

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>

<xsl:template match="/"> 
    <xsl:text>GlobalID,ServicePointName&#xa;</xsl:text>

    <!-- the rest -->

</xsl:template>

</xsl:stylesheet>

(which is also XSLT 1.0 compatible).

None of this explains why your attempt to use an internal node wouldn't work.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
-1

I've never tried to do this, but just looking at the documentation for the document() function it says this:

document()  Used to access the nodes in an external XML document

Edit: I jumped the gun as pointed out by comments below. There is another question facing the same problems:

XSLT document('') function doesn't work

Community
  • 1
  • 1
Bensonius
  • 1,501
  • 1
  • 15
  • 39