I have an XML file what I want to filter by an XML file what I pass as parameter to my XSLT 2.0 file with Saxon CE's setParameter function:
xsltData = Saxon.requestXML("filter.xsl");
xmlData = Saxon.requestXML("xmlfile.xml");
var xsltProcessor = Saxon.newXSLT20Processor(xsltData);
xsltProcessor.setParameter(null, "src", "filterxml.xml");
var result = xsltProcessor.transformToDocument(xmlData);
Parameter XML File:
<?xml version="1.0" encoding="UTF-8"?>
<Items>
<Item SrcName="itemname1" NewName="newitemname1"></Item>
<Item SrcName="itemname2" NewName="newitemname2"></Item>
<Item SrcName="itemname3" NewName="newitemname3"></Item>
</Items>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://www.mynamespace"
xmlns="http://www.mynamespace">
<xsl:strip-space elements="*" />
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" name="xml" />
<xsl:param name="src"></xsl:param>
<xsl:variable name="filter-doc" select="if (doc-available($src)) then doc($src) else ()"/>
<xsl:variable name="Items" select="$filter-doc/Items"></xsl:variable>
<xsl:template match="/">
<xsl:apply-templates select="$Items/Item"/>
</xsl:template>
</xsl:stylesheet>
The problem is, that I have an xpath-default-namespace in the XSLT file, with this I can't access $Items/Item. If I add the namespace xmlns="http://www.mynamespace" to the element everything is working fine. Is there a way to make this work without adding the namespace to my parameterxml? I know that in the setParameter function the first parameter is namespace, but even if I set a namespace here nothing changes in the result.
Is there any possibility to add the namespace to $Items with XSLT?