1
votes

For some reason, base-uri() is not returning the uri of the source file when I run an XSLT (using XSLT2, Saxon 9.4 PE).

Here is my xslt test case

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
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:err="http://www.w3.org/2005/xqt-errors"
exclude-result-prefixes="xs xdt err fn">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">

<xsl:value-of select="base-uri()"></xsl:value-of>
</xsl:template>

When I run this on a source xml file, I just get

<?xml version="1.0" encoding="UTF-8"?>

Note that I am able to retrieve the stylesheet URI just fine using base-uri(document('')).

I have also had no success using document-uri(/) either.

UPDATE: looks like there is definitely something amiss. It seems that nothing I do gets the processor to look in the SOURCE directory.

When I try "document('Dummy.xml',.) , it says it cannot find "Dummy.xml" even though that is the name of the source file.

Maybe I should re-install the jar file or email EditiX support.

1
I need to get the baseuri please help me give me some suggestion... - Sriram S
To get the base-uri of the source xml, you should just be able to use base-uri(). This is what I use to reliably get the directory of the source xml file: <xsl:variable name="path" select="replace(base-uri(),'(.*/)[^/]+?.xml','$1')"/> - David R
If you are looking for the uri of the XSL stylesheet, static-base-uri() should work most of the time. - David R

1 Answers

1
votes

How do you use Saxon, from the command line or within your own code? How do you provide the input document to Saxon? When I run Saxon 9.4 HE Java from the command line (e.g. java -jar saxon9.he input.xml sheet.xsl) I get the some meaningful output (like <?xml version="1.0" encoding="UTF-8"?>file:/C:/Users/UserName/Documents/xslt/input.xml).