473,324 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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
3 3010
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jim Bancroft | last post by:
Sorry for the basic nature of this question. I know XSL can do this, but I don't recall a good method... Say I have an xml structure like this: <folder_structure> <folder name="folder1">...
1
by: Ken Larson | last post by:
I have a question about using XSL to extract information from an SVG (XML) file that has a DOCTYPE/DTD declaration. I am able to do this successfully if I write my own SVG files without such a...
1
by: Philip | last post by:
Hi, I am trying to output certain nodes inside another. I have an xml template with field definitions for a form, and this includes textfields, labels, checkboxes etc plus fieldssets. I defined...
2
by: kj | last post by:
Suppose I have some XML document that contains tags of the form <... xmlns:foo="http://www.bar.org/foo"> <... xmlns:foo="baz"> <... xmlns:frobozz="http://www.bar.org/foo"> What's the...
8
by: Tjerk Wolterink | last post by:
Hello all, how does xsl handle white space? I know you can set domething like this for nice indentation: <xsl:output method="xhtml" indent="yes"/> But know i have xsl code like this:
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
10
by: William Krick | last post by:
I am writing an XSL transform that converts XML data about vehicles into XML data that will fill printed forms. The default form can handle up to 5 vehicles which I handle using subscripts... ...
6
by: Christoph | last post by:
I'm trying to come up with a stylesheet where, when the rows are displayed, duplicate game names are not shown on subsequent rows. It works but doesn't work properly. If I sort the data using...
5
by: Simon Brooke | last post by:
This is supposed to be a very simple XSL stylesheet to strip styling information out of HTML documents - it could not be more basic. And yet, it doesn't work. I'm obviously getting something very...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.