473,563 Members | 2,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hello i have xml code like this:

<page:page xmlns:page="nam espacefor 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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="htt p://www.wolterinkwe bdesign.com/xml/page"
xmlns:menu="htt p://www.wolterinkwe bdesign.com/xml/menu">

[cut]

<!--
! Matches a text section.
! Converts the page block to a html styled section of text
!-->
<xsl:template match="page:sec tion">
<h1><xsl:valu e-of select="page:he ader"/></h1>
<div>
<xsl:apply-templates/>
</div>
</xsl:template>

<!--
! Matches the content element in a section element
!-->
<xsl:template match="page:con tent">
<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 3032
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="nam espacefor page">
needs to be...
<page:page xmlns:page="htt p://www.wolterinkwe bdesign.com/xml/page">

or...
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="htt p://www.wolterinkwe bdesign.com/xml/page"
xmlns:menu="htt p://www.wolterinkwe bdesign.com/xml/menu">
needs to be...
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="nam espacefor page"
xmlns:menu="htt p://www.wolterinkwe bdesign.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***@wolterin kwebdesign.com> wrote in message
news:41******** *************** @news.wanadoo.n l...
Hello i have xml code like this:

<page:page xmlns:page="nam espacefor 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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="htt p://www.wolterinkwe bdesign.com/xml/page"
xmlns:menu="htt p://www.wolterinkwe bdesign.com/xml/menu">

[cut]

<!--
! Matches a text section.
! Converts the page block to a html styled section of text
!-->
<xsl:template match="page:sec tion">
<h1><xsl:valu e-of select="page:he ader"/></h1>
<div>
<xsl:apply-templates/>
</div>
</xsl:template>

<!--
! Matches the content element in a section element
!-->
<xsl:template match="page:con tent">
<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="nam espacefor page">
needs to be...
<page:page xmlns:page="htt p://www.wolterinkwe bdesign.com/xml/page">

or...
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="htt p://www.wolterinkwe bdesign.com/xml/page"
xmlns:menu="htt p://www.wolterinkwe bdesign.com/xml/menu">
needs to be...
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="nam espacefor page"
xmlns:menu="htt p://www.wolterinkwe bdesign.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***@wolterin kwebdesign.com> wrote in message
news:41******** *************** @news.wanadoo.n l...
Hello i have xml code like this:

<page:page xmlns:page="nam espacefor page">
<page:section >
<page:heade r>
<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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="h ttp://www.wolterinkwe bdesign.com/xml/page"
xmlns:menu="h ttp://www.wolterinkwe bdesign.com/xml/menu">

[cut]

<!--
! Matches a text section.
! Converts the page block to a html styled section of text
!-->
<xsl:templa te match="page:sec tion">
<h1><xsl:valu e-of select="page:he ader"/></h1>
<div>
<xsl:apply-templates/>
</div>
</xsl:template>

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

<!--
! Matches all xhtml tags and copies them
!-->
<xsl:templa te 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***@wolterin kwebdesign.com> wrote in message
news:41******** *************** @news.wanadoo.n l... 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="nam espacefor page">
needs to be...
<page:page xmlns:page="htt p://www.wolterinkwe bdesign.com/xml/page">

or...
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="htt p://www.wolterinkwe bdesign.com/xml/page"
xmlns:menu="htt p://www.wolterinkwe bdesign.com/xml/menu">
needs to be...
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="nam espacefor page"
xmlns:menu="htt p://www.wolterinkwe bdesign.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***@wolterin kwebdesign.com> wrote in message
news:41******** *************** @news.wanadoo.n l...
Hello i have xml code like this:

<page:page xmlns:page="nam espacefor page">
<page:section >
<page:heade r>
<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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="h ttp://www.wolterinkwe bdesign.com/xml/page"
xmlns:menu="h ttp://www.wolterinkwe bdesign.com/xml/menu">

[cut]

<!--
! Matches a text section.
! Converts the page block to a html styled section of text
!-->
<xsl:templa te match="page:sec tion">
<h1><xsl:valu e-of select="page:he ader"/></h1>
<div>
<xsl:apply-templates/>
</div>
</xsl:template>

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

<!--
! Matches all xhtml tags and copies them
!-->
<xsl:templa te 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
1627
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"> <file name="myfile"/> </folder> <folder name="folder2">
1
2688
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 declaration. However, I would like to extract some parts of an SVG file exported by illustrator. When I try this, my XSL file is no longer able to...
1
1885
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 them like this: >>>> XML SNIPPET >>>> <fields>
2
2966
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 XPath expression to select the namespace nodes with prefix "foo"? And what's the XPath expression to select the
8
2933
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
2870
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 - "xmlns="http://tempuri.org/nameOfRoot.xsd" I have no idea what its pointing to & what is tempuri.org? So when this tag is in my xml tag my xpath query never works. But...
10
1898
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... <xsl:for-each select="VEHICLE"> <!-- spit out some stuff about this vehicle --> </xsl:for-each> <xsl:for-each select="VEHICLE">
6
1898
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 <xsl:sortprior to processing, it's not checking against the previous row after the sort but instead the previous row from the original data set. Here...
5
2900
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 basic wrong and for the life of me I can't see it. Please, somebody, cast your eyes over this and tell me what's wrong! First, the XSL stylesheet:...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.