Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Default namespace ID as external parameter

7 views
Skip to first unread message

Petr Danes

unread,
Dec 7, 2009, 7:24:34 AM12/7/09
to
I have a set of XML files that I am processing with an XSL transform. They
have a default namespace, so my XSL transform must contain the declaration:

xpath-default-namespace="urn:CZ-RVV-IS-VaV-XML-NS:data-1.2.2"

The problem is that this value changes from time to time, and my transform
suddenly stops working, until I look at an example from the new file,
extract this namespace ID and put it in the transform, whereby the transform
stops working for old files. Is there a way to pass this as a parameter? I
have tried the parameter syntaxes that I looked up in various tutorials, but
none have worked for this particular use.

Pete

--
This e-mail address is fake, to keep spammers and their address harvesters
out of my hair. If you want to get in touch personally, I am 'pdanes' and I
use yahoo mail. But please use the newsgroup when possible, so that all may
benefit from the exchange of ideas.


Petr Danes

unread,
Dec 7, 2009, 10:19:10 AM12/7/09
to
Further reading is not encouraging, everything seems to indicate that this
is a compile-time value, not manipulable once processing starts. (If I'm
wrong and this can be done, I'd love to hear it.)

But a two-pass solution seems a popular way to deal with similar issues -
making a transform to re-configure the original transform, then executing
the changed transform. Since the XSL transform is XML, theoretically easily
changed with XSL, this might be the way to go. I need to get this first line
in the source document:

<dodavka xmlns="urn:CZ-RVV-IS-VaV-XML-NS:data-1.2.1"
xmlns:v="urn:xmlns:mathan.vklap.annotations-1.0" v:faze="finalni"
struktura="RIV08A">

and extract the default namespace declaration,
[xmlns="urn:CZ-RVV-IS-VaV-XML-NS:data-1.2.1"] part, get its value and insert
it as an xpath-default-namespace attribute into the first line of the
original transform:

<xsl:transform version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:v="urn:xmlns:mathan.vklap.annotations-1.0"
xpath-default-namespace="urn:CZ-RVV-IS-VaV-XML-NS:data-1.2.2"
>

This, in fact, is exactly a case where I need such a change. The source XML
namespace ends in 1.2.1 but the transform has namespace ...1.2.2, which
makes the whole transform do nothing, since it's looking at the wrong
namespace.

Is this a viable path, or will I run into the same namespace problems? I'm
trying it now, but no results yet. I'm using Saxon, but not getting anything
at all - no error messages and no output. Here's the XSL as I have it now:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:templates match="dodavka">
<xsl:value-of select="@xmlns">
</xsl:template>
</xsl:transform>

Pete

"Petr Danes" <skrusp...@no.spam> p锟絜 v diskusn锟絤 p锟斤拷sp锟絭ku
news:eMnz8gzd...@TK2MSFTNGP04.phx.gbl...

Martin Honnen

unread,
Dec 7, 2009, 10:26:10 AM12/7/09
to
Petr Danes wrote:

> <dodavka xmlns="urn:CZ-RVV-IS-VaV-XML-NS:data-1.2.1"
> xmlns:v="urn:xmlns:mathan.vklap.annotations-1.0" v:faze="finalni"
> struktura="RIV08A">
>
> and extract the default namespace declaration,
> [xmlns="urn:CZ-RVV-IS-VaV-XML-NS:data-1.2.1"] part,

> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"


> >
> <xsl:templates match="dodavka">
> <xsl:value-of select="@xmlns">
> </xsl:template>
> </xsl:transform>

In the XSLT/XPath/XQuery data model namespace declarations are not
modelled as attributes.
If you want to find the namespace URI of the context node then simply use
namespace-uri()
or
namespace-uri(.)

--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/

Petr Danes

unread,
Dec 7, 2009, 11:00:12 AM12/7/09
to
Hello Martin,

thanks, I managed toget as far as this error message from Saxon:

Warning: on line 6 of XfXf.xsl:
The attribute axis starting at a document node will never select anything

Not sure why I was not getting anything before, probably mistyped something.

Now the new transform runs, but doesn't produce anything sensible. Here's
what I'm using:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="2.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:template match="/">
<xsl:value-of select="namespace-uri()"/>
</xsl:template>
</xsl:transform>

Tried it both with and with out the dot, same results. Output file contains
only:

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

and nothing else.

Pete


"Martin Honnen" <maho...@yahoo.de> p�se v diskusn�m pr�spevku
news:%232B6bG1...@TK2MSFTNGP05.phx.gbl...

Petr Danes

unread,
Dec 7, 2009, 11:07:37 AM12/7/09
to
Scratch that last, I got it. No idea what was up, it just started working,
and I'm getting the URI. Hope I can get it into the transform now.

Pete

"Martin Honnen" <maho...@yahoo.de> p�se v diskusn�m pr�spevku
news:%232B6bG1...@TK2MSFTNGP05.phx.gbl...

Martin Honnen

unread,
Dec 7, 2009, 11:12:31 AM12/7/09
to
Petr Danes wrote:

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

You need to match on an element or attribute e.g.
<xsl:template match="/*">


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

or maybe
<xsl:template match="/*:dodavka">


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

If you want to match on the document node then use
<xsl:template match="/">
<xsl:value-of select="namespace-uri(*)"/>
</xsl:template>

Petr Danes

unread,
Dec 7, 2009, 11:36:45 AM12/7/09
to
Thank you. What I got working was this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>

<xsl:template match="*">


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

</xsl:transform>

Lots of ways to skin a cat. Now I'm working on getting it into the output.

Pete


"Martin Honnen" <maho...@yahoo.de> p�se v diskusn�m pr�spevku

news:%23jUnVg1...@TK2MSFTNGP05.phx.gbl...

0 new messages