467,132 Members | 1,149 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,132 developers. It's quick & easy.

XSL: XPath copying all nodes that are not in a namespace

Hello i have xml code like this:

<page:page xmlns:page="namespacefor page">
<page:section>
<page:header>
<b>Hello</b>There
</page:header>
<page:content>
--- HTML CODE like:
<i>Y</i>es i like bla bal <center>bla</center><img> alblalba
</page:content>
</page:section>
</page:page>
Now i want to convert this page:page xml page to a xhtml page,
but i want all the xhtml tags like <b> to stay intact, how can i select
these tags to becopied in the xsl.
My xsl looks now like this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="http://www.wolterinkwebdesign.com/xml/page"
xmlns:menu="http://www.wolterinkwebdesign.com/xml/menu">

[cut]

<!--
! Matches a text section.
! Converts the page block to a html styled section of text
!-->
<xsl:template match="page:section">
<h1><xsl:value-of select="page:header"/></h1>
<div>
<xsl:apply-templates/>
</div>
</xsl:template>

<!--
! Matches the content element in a section element
!-->
<xsl:template match="page:content">
<xsl:apply-templates/>
</xsl:template>

<!--
! Matches all xhtml tags and copies them
!-->
<xsl:template match=".[namespace-uri('')!=page]">
<xsl:copy-of select="."/>
</xsl:template>

[cut]
</xsl:stylesheet>

Well i tried to copy all elemetns who are not in the page namespace but
this xpath expression: .[namespace-uri('')!=page] does not work.

How should i copy all xhtml tags??

The output should be like this:
<html>
<h1>
<b>Hello</b>There
</h1>
<div><p>

--- HTML CODE like:
<i>Y</i>es i like bla bal <center>bla</center><img> alblalba
</p></div>
</html>
Pleaz help me
Jul 20 '05 #1
  • viewed: 2837
Share:
3 Replies
Hi,

First off, namespaces are matched by their URI rather than their prefix - so
even if you use the 'page' prefix in both XML and XSL they won't match
unless the namespace URIs are also the same, so...
either...
<page:page xmlns:page="namespacefor page">
needs to be...
<page:page xmlns:page="http://www.wolterinkwebdesign.com/xml/page">

or...
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="http://www.wolterinkwebdesign.com/xml/page"
xmlns:menu="http://www.wolterinkwebdesign.com/xml/menu">
needs to be...
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="namespacefor page"
xmlns:menu="http://www.wolterinkwebdesign.com/xml/menu">
and to the main issue, your template for catching elements not bound to the
'page' namespace probably needs to look something like...

<!--
! Matches all xhtml tags and copies them
!-->
<xsl:template match="*[namespace-uri(.) != namespace::page]">
<xsl:copy-of select="."/>
</xsl:template>
HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Tjerk Wolterink" <tj***@wolterinkwebdesign.com> wrote in message
news:41***********************@news.wanadoo.nl...
Hello i have xml code like this:

<page:page xmlns:page="namespacefor page">
<page:section>
<page:header>
<b>Hello</b>There
</page:header>
<page:content>
--- HTML CODE like:
<i>Y</i>es i like bla bal <center>bla</center><img> alblalba
</page:content>
</page:section>
</page:page>
Now i want to convert this page:page xml page to a xhtml page,
but i want all the xhtml tags like <b> to stay intact, how can i select
these tags to becopied in the xsl.
My xsl looks now like this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="http://www.wolterinkwebdesign.com/xml/page"
xmlns:menu="http://www.wolterinkwebdesign.com/xml/menu">

[cut]

<!--
! Matches a text section.
! Converts the page block to a html styled section of text
!-->
<xsl:template match="page:section">
<h1><xsl:value-of select="page:header"/></h1>
<div>
<xsl:apply-templates/>
</div>
</xsl:template>

<!--
! Matches the content element in a section element
!-->
<xsl:template match="page:content">
<xsl:apply-templates/>
</xsl:template>

<!--
! Matches all xhtml tags and copies them
!-->
<xsl:template match=".[namespace-uri('')!=page]">
<xsl:copy-of select="."/>
</xsl:template>

[cut]
</xsl:stylesheet>

Well i tried to copy all elemetns who are not in the page namespace but
this xpath expression: .[namespace-uri('')!=page] does not work.

How should i copy all xhtml tags??

The output should be like this:
<html>
<h1>
<b>Hello</b>There
</h1>
<div><p>

--- HTML CODE like:
<i>Y</i>es i like bla bal <center>bla</center><img> alblalba
</p></div>
</html>
Pleaz help me

Jul 20 '05 #2
Marrow Thanks,

i know namespaces are bound to the URI, i posted it wrong,
the namespace is use is: http://www.wolterinkwebdesign.com/xml/page

But just a question because i'm curiuous:
The uri does not have to exists does, it?
URI's are just used for namespaces to have an unique identifier.
Am i right?
Or do developers often place their dtd, or schema's in the uri path??

Marrow wrote:
Hi,

First off, namespaces are matched by their URI rather than their prefix - so
even if you use the 'page' prefix in both XML and XSL they won't match
unless the namespace URIs are also the same, so...
either...
<page:page xmlns:page="namespacefor page">
needs to be...
<page:page xmlns:page="http://www.wolterinkwebdesign.com/xml/page">

or...
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="http://www.wolterinkwebdesign.com/xml/page"
xmlns:menu="http://www.wolterinkwebdesign.com/xml/menu">
needs to be...
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="namespacefor page"
xmlns:menu="http://www.wolterinkwebdesign.com/xml/menu">
and to the main issue, your template for catching elements not bound to the
'page' namespace probably needs to look something like...

<!--
! Matches all xhtml tags and copies them
!-->
<xsl:template match="*[namespace-uri(.) != namespace::page]">
<xsl:copy-of select="."/>
</xsl:template>
HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Tjerk Wolterink" <tj***@wolterinkwebdesign.com> wrote in message
news:41***********************@news.wanadoo.nl...
Hello i have xml code like this:

<page:page xmlns:page="namespacefor page">
<page:section>
<page:header>
<b>Hello</b>There
</page:header>
<page:content>
--- HTML CODE like:
<i>Y</i>es i like bla bal <center>bla</center><img> alblalba
</page:content>
</page:section>
</page:page>
Now i want to convert this page:page xml page to a xhtml page,
but i want all the xhtml tags like <b> to stay intact, how can i select
these tags to becopied in the xsl.
My xsl looks now like this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="http://www.wolterinkwebdesign.com/xml/page"
xmlns:menu="http://www.wolterinkwebdesign.com/xml/menu">

[cut]

<!--
! Matches a text section.
! Converts the page block to a html styled section of text
!-->
<xsl:template match="page:section">
<h1><xsl:value-of select="page:header"/></h1>
<div>
<xsl:apply-templates/>
</div>
</xsl:template>

<!--
! Matches the content element in a section element
!-->
<xsl:template match="page:content">
<xsl:apply-templates/>
</xsl:template>

<!--
! Matches all xhtml tags and copies them
!-->
<xsl:template match=".[namespace-uri('')!=page]">
<xsl:copy-of select="."/>
</xsl:template>

[cut]
</xsl:stylesheet>

Well i tried to copy all elemetns who are not in the page namespace but
this xpath expression: .[namespace-uri('')!=page] does not work.

How should i copy all xhtml tags??

The output should be like this:
<html>
<h1>
<b>Hello</b>There
</h1>
<div><p>

--- HTML CODE like:
<i>Y</i>es i like bla bal <center>bla</center><img> alblalba
</p></div>
</html>
Pleaz help me


Jul 20 '05 #3
Hi,
But just a question because i'm curiuous:
The uri does not have to exists does, it?
URI's are just used for namespaces to have an unique identifier.
Am i right?
Yes, you are right - URI stands for unique resource identifier. Nothing has
to be there at all. People use URLs as URIs generally because this gives
some garauntee of uniqueness - and they tend to choose URIs based on their
organisations URL because they have some control over it.
(see also: http://www.w3.org/TR/REC-xml-names/#ns-decl).
Or do developers often place their dtd, or schema's in the uri path??
Some do and some don't. So the general rule is - don't rely on the URI to
be a URL at which something will be found. The mechinisms for pointing to
DTD/Schemas is entirely different.

Cheers
Marrow

"Tjerk Wolterink" <tj***@wolterinkwebdesign.com> wrote in message
news:41***********************@news.wanadoo.nl... Marrow Thanks,

i know namespaces are bound to the URI, i posted it wrong,
the namespace is use is: http://www.wolterinkwebdesign.com/xml/page

But just a question because i'm curiuous:
The uri does not have to exists does, it?
URI's are just used for namespaces to have an unique identifier.
Am i right?
Or do developers often place their dtd, or schema's in the uri path??

Marrow wrote:
Hi,

First off, namespaces are matched by their URI rather than their prefix - so even if you use the 'page' prefix in both XML and XSL they won't match
unless the namespace URIs are also the same, so...
either...
<page:page xmlns:page="namespacefor page">
needs to be...
<page:page xmlns:page="http://www.wolterinkwebdesign.com/xml/page">

or...
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="http://www.wolterinkwebdesign.com/xml/page"
xmlns:menu="http://www.wolterinkwebdesign.com/xml/menu">
needs to be...
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="namespacefor page"
xmlns:menu="http://www.wolterinkwebdesign.com/xml/menu">
and to the main issue, your template for catching elements not bound to the 'page' namespace probably needs to look something like...

<!--
! Matches all xhtml tags and copies them
!-->
<xsl:template match="*[namespace-uri(.) != namespace::page]">
<xsl:copy-of select="."/>
</xsl:template>
HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Tjerk Wolterink" <tj***@wolterinkwebdesign.com> wrote in message
news:41***********************@news.wanadoo.nl...
Hello i have xml code like this:

<page:page xmlns:page="namespacefor page">
<page:section>
<page:header>
<b>Hello</b>There
</page:header>
<page:content>
--- HTML CODE like:
<i>Y</i>es i like bla bal <center>bla</center><img> alblalba
</page:content>
</page:section>
</page:page>
Now i want to convert this page:page xml page to a xhtml page,
but i want all the xhtml tags like <b> to stay intact, how can i select
these tags to becopied in the xsl.
My xsl looks now like this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="http://www.wolterinkwebdesign.com/xml/page"
xmlns:menu="http://www.wolterinkwebdesign.com/xml/menu">

[cut]

<!--
! Matches a text section.
! Converts the page block to a html styled section of text
!-->
<xsl:template match="page:section">
<h1><xsl:value-of select="page:header"/></h1>
<div>
<xsl:apply-templates/>
</div>
</xsl:template>

<!--
! Matches the content element in a section element
!-->
<xsl:template match="page:content">
<xsl:apply-templates/>
</xsl:template>

<!--
! Matches all xhtml tags and copies them
!-->
<xsl:template match=".[namespace-uri('')!=page]">
<xsl:copy-of select="."/>
</xsl:template>

[cut]
</xsl:stylesheet>

Well i tried to copy all elemetns who are not in the page namespace but
this xpath expression: .[namespace-uri('')!=page] does not work.

How should i copy all xhtml tags??

The output should be like this:
<html>
<h1>
<b>Hello</b>There
</h1>
<div><p>

--- HTML CODE like:
<i>Y</i>es i like bla bal <center>bla</center><img> alblalba
</p></div>
</html>
Pleaz help me


Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jim Bancroft | last post: by
1 post views Thread by Philip | last post: by
2 posts views Thread by kj | last post: by
8 posts views Thread by Tjerk Wolterink | last post: by
2 posts views Thread by ree32 | last post: by
10 posts views Thread by William Krick | last post: by
6 posts views Thread by Christoph | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.