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

T

Tjerk Wolterink

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
 
M

Marrow

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 said:
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
 
T

Tjerk Wolterink

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??
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



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
 
M

Marrow

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 said:
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??
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



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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top