[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Using multiple xpath-default-namespace
Subject: Re: [xsl] Using multiple xpath-default-namespace From: Terry Badger <terry_badger@xxxxxxxxx> Date: Thu, 23 Jan 2014 05:27:07 -0800 (PST) |
Pankaj, Create two stylesheets that are almost identical except for the default namespace. Import each into a "main' stylesheet. Each sub stylesheet will handle the same local-name element that is in their namespace. Here is a sample: xml file <?xml version="1.0" encoding="UTF-8"?> <wrapper> <name1xmlns="ns1">This is ns1</name1> <name1xmlns="ns2">This is ns2</name1> </wrapper> ns1.xsd<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"xpath-default-namespace="ns1"> <xsl:templatematch="name1"> <xsl:text>This will get the value in ns1 </xsl:text> <xsl:value-ofselect="."/> </xsl:template> </xsl:stylesheet> ns2.xsl<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"xpath-default-namespace="ns2"> <xsl:templatematch="name1"> <xsl:text>This will get the value in ns2 </xsl:text> <xsl:value-ofselect="."/> </xsl:template> </xsl:stylesheet> ns-master.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"version="2.0"> <xsl:importhref="ns1.xsl"/> <xsl:importhref="ns2.xsl"/> <xsl:templatematch="/"name="main"> <xsl:apply-templates/> </xsl:template> </xsl:stylesheet> Terry On Thursday, January 23, 2014 6:54 AM, Martin Honnen <Martin.Honnen@xxxxxx> wrote: Pankaj Chaturvedi wrote: > May be I sound bit stupid but is there a way using multiple > "xpath-default-namespace" in one stylesheet. I have a case wherein I > have multiple XML files following same DTD, but with different version, > difference mainly being the different "xmlns". There are slight other > changes and I have written style sheet which I was thinking of using on > both version of XML but that does not seems to be case. Tried using > local-name() but it seems to fine on root element. > > I can though segregate or write two different XSLT to handle both case > but I thought of cross check the possibility. It is possible to use a wildcard <xsl:template match="*:foo"> which would match elements with local name "foo" in any namespace. And you can use xpath-default-namespace with different value in different places in a single stylesheet.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Using multiple xpath-defa, Martin Honnen | Thread | Re: [xsl] Using multiple xpath-defa, Michael Kay |
Re: [xsl] Using multiple xpath-defa, Martin Honnen | Date | Re: [xsl] Using multiple xpath-defa, Michael Kay |
Month |