XSL won't write xmlns:xsl? - xslt

How do I write the XSL namespace in my output?
I'm using XSL to analyze an XSL document and report problems it finds, including copying the node. The problem is that I can't get xmlns:xsl="http://www.w3.org/1999/XSL/Transform" written into the output's root node, which means it gets repeated every time I copy an xsl:* element.
This doesn't seem to happen with other namespaces. For example, take the following XSL
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:custom="custom uri" xmlns:custom2="custom2 uri" exclude-result-prefixes="" version="3.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/" name="xsl:initial-template">
<custom:element xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:element name="custom2:function">
<xsl:attribute name="name">whatever</xsl:attribute>
</xsl:element>
<xsl:element name="custom2:function">
<xsl:attribute name="name">whatever2</xsl:attribute>
</xsl:element>
</custom:element>
</xsl:template>
</xsl:stylesheet>
When run against any XML document, I get what I expect except that xmlns:xsl is missing from custom:element even though I specify it and exclude-result-prefixes is explicitly blank... but that's fine, it's not used in the output.
<custom:element xmlns:custom="custom uri" xmlns:custom2="custom2 uri">
<custom2:function name="whatever"/>
<custom2:function name="whatever2"/>
</custom:element>
However, if I replace both name="custom2:function" with name="xsl:function" like so...
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:custom="custom uri" xmlns:custom2="custom2 uri" exclude-result-prefixes="" version="3.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/" name="xsl:initial-template">
<custom:element xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:element name="xsl:function">
<xsl:attribute name="name">whatever</xsl:attribute>
</xsl:element>
<xsl:element name="xsl:function">
<xsl:attribute name="name">whatever2</xsl:attribute>
</xsl:element>
</custom:element>
</xsl:template>
</xsl:stylesheet>
then xmlns:xsl is still missing from custom:element and I get
<custom:element xmlns:custom="custom uri" xmlns:custom2="custom2 uri">
<xsl:function xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="whatever"/>
<xsl:function xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="whatever2"/>
</custom:element>
instead of what I want:
<custom:element xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:custom="custom uri" xmlns:custom2="custom2 uri">
<xsl:function name="whatever"/>
<xsl:function name="whatever2"/>
</custom:element>
How do I change my stylesheet to declare xmlns:xsl="http://www.w3.org/1999/XSL/Transform" I the root node?

With Saxon a namespace alias helps:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:custom="custom-uri" xmlns:custom2="custom2-uri" version="3.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl" xmlns:axsl="http://www.w3.org/1999/XSL/Transform-alias"/>
<xsl:template match="/" name="xsl:initial-template">
<custom:element xmlns:axsl="http://www.w3.org/1999/XSL/Transform-alias">
<xsl:element name="xsl:function">
<xsl:attribute name="name">whatever</xsl:attribute>
</xsl:element>
<xsl:element name="xsl:function">
<xsl:attribute name="name">whatever2</xsl:attribute>
</xsl:element>
</custom:element>
</xsl:template>
</xsl:stylesheet>
https://xsltfiddle.liberty-development.net/gVhEaiX outputs
<custom:element xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:custom="custom-uri"
xmlns:custom2="custom2-uri">
<xsl:function name="whatever"/>
<xsl:function name="whatever2"/>
</custom:element>
Most times you would just put the namespace declaration on the root element with e.g.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:custom="custom-uri" xmlns:custom2="custom2-uri" version="3.0"
xmlns:axsl="http://www.w3.org/1999/XSL/Transform-alias">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl" />
<xsl:template match="/" name="xsl:initial-template">
<custom:element>
<xsl:element name="xsl:function">
<xsl:attribute name="name">whatever</xsl:attribute>
</xsl:element>
<xsl:element name="xsl:function">
<xsl:attribute name="name">whatever2</xsl:attribute>
</xsl:element>
</custom:element>
</xsl:template>
</xsl:stylesheet>
I was not sure whether you want to restrict it to a certain element so the first sample declares it on that element and then of course additionally on the xsl:namespace-alias so that it makes sense.

Related

XSLT - add prefix for namespace

Here's my input XML:
<?xml version="1.0" encoding="UTF-8"?>
<Sync
xmlns="http://schema.infor.com/InforOAGIS/2" languageCode="en-US" versionID="2.8.0">
<Data>
<ID>0001</ID>
<Text>ABCD</Text>
</Data>
</Sync>
And here's my expected outcome:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:Sync xmlns:ns0="http://schema.infor.com/InforOAGIS/2"
languageCode="en-US"
versionID="2.8.0">
<DataArea xmlns:dns="http://schema.infor.com/InforOAGIS/2" xmlns="">
<ID>0001</ID>
<Text>ABCD</Text>
</DataArea>
</ns0:Sync>
My current XSLT as below (https://xsltfiddle.liberty-development.net/nbiE19N).
There are 2 problems:
I have the extra xmlns="" in DataArea element. I only want to add the dns namespace.
I cannot add the ns0 prefix for my namespace
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/*:Sync">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*:Sync/*:Data">
<DataArea>
<xsl:namespace name="dns" select="'http://schema.infor.com/InforOAGIS/2'"/>
<ID>
<xsl:value-of select="/*:Sync/*:Data/*:ID"/>
</ID>
<Text>
<xsl:value-of select="/*:Sync/*:Data/*:Text"/>
</Text>
</DataArea>
</xsl:template>
</xsl:stylesheet>
Any suggestion is appreciated!
Does this return the expected result:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://schema.infor.com/InforOAGIS/2">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/Sync">
<ns0:Sync xmlns:ns0="http://schema.infor.com/InforOAGIS/2">
<xsl:copy-of select="#*"/>
<xsl:apply-templates/>
</ns0:Sync>
</xsl:template>
<xsl:template match="Data">
<DataArea xmlns:dns="http://schema.infor.com/InforOAGIS/2">
<xsl:apply-templates/>
</DataArea>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
P.S. I am not sure why you need the xmlns:dns="http://schema.infor.com/InforOAGIS/2" declaration; it's not being used anywhere.

XSLT to replace a namespace and also add a new (unused) namespace

I want to replace the namespace of the following XML Document
<?xml version="1.0" encoding="UTF-8"?>
<ns0:Document xmlns:ns0="http://mydata.com/H2H/Automation">
<CstmrCdtTrfInitn>
<GrpHdr>
</GrpHdr>
</CstmrCdtTrfInitn>
</ns0:Document>
with the following
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CstmrCdtTrfInitn>
<GrpHdr>
</GrpHdr>
</CstmrCdtTrfInitn>
</Document>
Any idea about XSLT which can convert this?
I have tried the following XSL, but it is adding the namespace with second Node and also not able to remove first namespace.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes"/>
<xsl:template match="/*">
<xsl:element name="{local-name()}" namespace="http://www.w3.org/2001/XMLSchema-instance">
<xsl:copy-of select="./*" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Your requirement can be a bit tricky: replacing the default namespace of the Document element is straightforward. But adding the unused xslns:xsi namespace in XSLT-1.0 requires the EXSLT extension and a special technique explained by Michael Kay in reply to this question. It involves creating an unused element in a global variable whose namespace is then copied in the template replacing the default namespace. In XSLT-2.0 and above this would be easier (see below).
The EXSLT extension is not available in all XSLT-1.0 processors. But it is necessary to create a node-set from the variable.
So all namespaces are to be defined in the xsl:stylesheet element, and then the root element (here ns0:Document) is matched by a template and replaced with its local-name() part with the new default namespace added, followed by copying the "dummy" namespace of the element defined in the variable.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://mydata.com/H2H/Automation" xmlns:urn="urn:iso:std:iso" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ext="http://exslt.org/common">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<!-- identity template (except elements)-->
<xsl:template match="node()[not(self::*)]|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*" />
</xsl:copy>
</xsl:template>
<xsl:variable name="nsXSI">
<xsl:element name="xsi:dummy" namespace="http://www.w3.org/2001/XMLSchema-instance" />
</xsl:variable>
<xsl:template match="ns0:*|*">
<xsl:element name="{local-name()}" namespace="urn:iso:std:iso">
<xsl:copy-of select="ext:node-set($nsXSI)/*/namespace::xsi" />
<xsl:apply-templates select="node() | #*" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Output should be as expected, even in XSLT-1.0:
<Document xmlns="urn:iso:std:iso" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CstmrCdtTrfInitn>
<GrpHdr>
</GrpHdr>
</CstmrCdtTrfInitn>
</Document>
The simplified solution requires an XSLT-2.0 capable processor. Then you can use the xsl:namespace instruction as follows and don't need the "dummy" variable:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://mydata.com/H2H/Automation">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<!-- identity template (except elements)-->
<xsl:template match="node()[not(self::element())]|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*" />
</xsl:copy>
</xsl:template>
<xsl:template match="ns0:*|*">
<xsl:element name="{local-name(.)}" namespace="urn:iso:std:iso">
<xsl:namespace name="xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:namespace>
<xsl:apply-templates select="node() | #*" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
The output is the same.
The above XSLT-2.0 solution could be further simplified by using XSLT-3.0+'s xsl:mode to replace the identity template with
<xsl:mode on-no-match="shallow-copy"/>
Is there a reason why you cannot do simply:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://mydata.com/H2H/Automation"
exclude-result-prefixes="ns0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="urn:iso:std:iso">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="/ns0:Document">
<Document xmlns="urn:iso:std:iso" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:apply-templates/>
</Document>
</xsl:template>
</xsl:stylesheet>

XSL transformation returns blank value

I have a problem to retrieve my input data when I do an xsl transformation.
This is my original xml input (input xml)
<?xml version="1.0" encoding="UTF-8"?> <ns2:pointOfSale
xmlns:ns2="http://example.net/.."
mode="CREATE" timestamp="2018-10-12T09:34:53.14+02:00"><ns2:id
type="AMP">15573</ns2:id></ns2:pointOfSale>
This is my output result (output xml)
<?xml version="1.0" encoding="utf-8"?><clients xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="setClients.xsd" encryptedData="N"><client clientID=""></client></clients>
this is my xsl
<?xml version="1.1" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns2="http://example.net/.."
exclude-result-prefixes="xs xd"
version="2.0">
<xsl:output method="xml" version="1.0" encoding="utf-8" omit-xml-declaration="no" indent="no" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<xsl:element name="clients">
<xsl:attribute
name="xsi:noNamespaceSchemaLocation">setClients.xsd</xsl:attribute>
<xsl:attribute name="encryptedData">N</xsl:attribute>
<xsl:element name="client">
<xsl:attribute name="clientID" >
<xsl:value-of select="ns2:id"/>
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Like you see, the value of element ID is empty ("")
What's the problem? is it the match() ? Maybe a problem of namespace?
thank you.
There are two reasons why <xsl:value-of select="id"/> is not returning anything.
Firstly, your template matches "/" which is the document node. This is the parent of the ns2:pointOfSale node in your XML. The document node does not have id as a child, so <xsl:value-of select="id"/> will not find anything. To fix this, you should match the root element (ns2:pointOfSale in this case) instead
<xsl:template match="/*">
The second issue is with namespaces. Assuming there was a namespace declaration in your XML of the form xmlns:ns2="xxx.xxxx" you would add the same declaration in your XSLT (on the xsl:stylesheet element) and then you could this.
<xsl:value-of select="ns2:id"/>
Without any reference to the namespace in your XSLT, it would be looking for an id element in no namespace.
Try this XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="xs xd"
xmlns:ns2="xxx.xxxx"
version="2.0">
<xsl:output method="xml" version="1.0" encoding="utf-8" omit-xml-declaration="no" indent="no" />
<xsl:strip-space elements="*" />
<xsl:template match="/*">
<xsl:element name="clients">
<xsl:attribute
name="xsi:noNamespaceSchemaLocation">setClients.xsd</xsl:attribute>
<xsl:attribute name="encryptedData">N</xsl:attribute>
<xsl:element name="client">
<xsl:attribute name="clientID" >
<xsl:value-of select="ns2:id"/>
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Actually, as you are using XSLT 2.0, you could use xpath-default-namespace instead, which would mean XSLT would treat any unprefixed element in a select expression as part of that namespace.
Try this too....
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="xs xd"
xpath-default-namespace="xxx.xxxx"
version="2.0">
<xsl:output method="xml" version="1.0" encoding="utf-8" omit-xml-declaration="no" indent="no" />
<xsl:strip-space elements="*" />
<xsl:template match="/*">
<xsl:element name="clients">
<xsl:attribute
name="xsi:noNamespaceSchemaLocation">setClients.xsd</xsl:attribute>
<xsl:attribute name="encryptedData">N</xsl:attribute>
<xsl:element name="client">
<xsl:attribute name="clientID" >
<xsl:value-of select="id"/>
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Better still, use Attribute Value Templates (and avoid the use of xsl:element) to simplify the XSLT to this...
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="xs xd"
xpath-default-namespace="xxx.xxxx"
version="2.0">
<xsl:output method="xml" version="1.0" encoding="utf-8" omit-xml-declaration="no" indent="no" />
<xsl:strip-space elements="*" />
<xsl:template match="/*">
<clients xsi:noNamespaceSchemaLocation="setClients.xsd" encryptedData="N">
<client clientID="{id}" />
</clients>
</xsl:template>
</xsl:stylesheet>

remove text from a node in input XML

i am trying to copy entire input xml in a string for further processing and also i have a requirement to remove text from a particular node (plancode) before copying in the variable. May I know how can i achieve this using xslt
INPUT XML:
<CallMember>
<PlanD>
<abcpr>you</abcpr>
<Desd>Protection</Desd>
<plancode>76789</plancode>
<plaDesc>goody</plaDesc>
</PlanD>
<fType>ONLINE</fType>
</CallMember>
XSLT i am trying :
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt" xmlns:func="http://exslt.org/functions" xmlns:dp="http://www.datapower.com/extensions" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:tglfn="http://test.com/tgl" xmlns:date="http://exslt.org/dates-and-times" exclude-result-prefixes="#all" extension-element-prefixes="dp regexp">
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>
<xsl:template match="/">
<xsl:variable name="InputRequest">
<xsl:copy-of select="."/>
</xsl:variable>
<xsl:variable name="modifiedRequest">
<xsl:copy-of select="."/>
<plancode></plancode>
</xsl:variable>
</xsl:template>
OUTput i am expecting in the modifiedRequest variable:
<CallMember>
<PlanD>
<abcpr>you</abcpr>
<Desd>Protection</Desd>
<plancode></plancode> <!-- this value needs to get emptied -->
<plaDesc>goody</plaDesc>
</PlanD>
<fType>ONLINE</fType>
</CallMember>
Use an identity template in combination with an (nearly) empty template for filtering and apply-templates to it:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt"
xmlns:func="http://exslt.org/functions"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:regexp="http://exslt.org/regular-expressions"
xmlns:tglfn="http://test.com/tgl"
xmlns:date="http://exslt.org/dates-and-times"
exclude-result-prefixes="#all" extension-element-prefixes="dp regexp">
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>
<!-- identity template -->
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*" />
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:variable name="InputRequest">
<xsl:copy-of select="."/>
</xsl:variable>
<!-- copies subtree except matching empty template -->
<xsl:variable name="modifiedRequest">
<xsl:copy>
<xsl:apply-templates select="node()|#*" />
</xsl:copy>
</xsl:variable>
</xsl:template>
<!-- (nearly) empty template copies only element without content -->
<xsl:template match="plancode">
<xsl:copy />
</xsl:template>
</xsl:stylesheet>

How to move out the dynamic result-document into the separate included or imported xsl file

I have a bunch of xsl files. I want to control an indent of result document centrally. I use now the code below in every xsl file. I have an xsl:template name="data" template in each file, but the content of this template is different. Is it possible to move out the content of xsl:template match="/" into the separate xsl file properly and import it in every xsl file. I tried but to no effect. Can someone advise me a working code?
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output name="indent" method="html" indent="yes" omit-xml-declaration="yes"/>
<xsl:output name="no_indent" method="html" indent="no" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:variable name="indent" select="//page/view-data/html-indent"/>
<xsl:if test="$indent='yes'">
<xsl:result-document format="indent" >
<xsl:call-template name="data"/>
</xsl:result-document>
</xsl:if>
<xsl:if test="$indent='no'">
<xsl:result-document format="no_indent" >
<xsl:call-template name="data"/>
</xsl:result-document>
</xsl:if>
</xsl:template>
<xsl:template name="data">
<!-- The content is different from file to file -->
</xsl:template>
</xsl:stylesheet>
You seem to have overlooked the fact that there is a much simpler way of doing this.
<xsl:param name="indent" select="'no'"/>
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:result-document indent="{$indent}">
....
</xsl:result-document>
</xsl:template>
and then supply the value of indent as a stylesheet parameter. And in fact there's an even simpler way: you can override the serialisation properties given in the stylesheet with properties supplied from the command line or the Java API: from the command line, just specify !indent=yes or !indent=no.
Yes it is:
Move the repeating code into a new .xsl e.g. main.xsl :
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output name="indent" method="html" indent="yes" omit-xml-declaration="yes"/>
<xsl:output name="no_indent" method="html" indent="no" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:variable name="indent" select="//page/view-data/html-indent"/>
<xsl:if test="$indent='yes'">
<xsl:result-document format="indent" >
<xsl:call-template name="data"/>
</xsl:result-document>
</xsl:if>
<xsl:if test="$indent='no'">
<xsl:result-document format="no_indent" >
<xsl:call-template name="data"/>
</xsl:result-document>
</xsl:if>
</xsl:template>
<xsl:template name="data"/>
</xsl:stylesheet>
Then in your other .xsl files simply use xsl:import at the top of your document :
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="file:///C:/Users/Stefanos/area51/main.xsl"/>
<!--Other stuff here-->
<xsl:template match="extra"/>
</xsl:stylesheet>
And add more code. Hope it helped :)
Ok, after separation, this is a main.xsl . I just simplified here the variable value.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output name="indent" method="html" indent="yes" omit-xml-declaration="yes"/>
<xsl:output name="no_indent" method="html" indent="no" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:variable name="indent" select="'yes'"/>
<xsl:if test="$indent='yes'">
<xsl:result-document format="indent" >
<xsl:call-template name="data"/>
</xsl:result-document>
</xsl:if>
<xsl:if test="$indent='no'">
<xsl:result-document format="no_indent" >
<xsl:call-template name="data"/>
</xsl:result-document>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
And next file, let's say 1.xsl
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="main.xsl"/>
<xsl:template name="data">
...
</xsl:template>
</xsl:stylesheet>
Here, I have an xsl transformation error