Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XSL: XPath copying all nodes that are not in a namespace (http://www.velocityreviews.com/forums/t168058-xsl-xpath-copying-all-nodes-that-are-not-in-a-namespace.html)

Tjerk Wolterink 10-21-2004 01:07 PM

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

Marrow 10-21-2004 03:37 PM

Re: XPath copying all nodes that are not in a namespace
 
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" <tjerk@wolterinkwebdesign.com> wrote in message
news:4177d0ff$0$45946$a344fe98@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




Tjerk Wolterink 10-21-2004 05:55 PM

Re: XPath copying all nodes that are not in a namespace
 
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" <tjerk@wolterinkwebdesign.com> wrote in message
> news:4177d0ff$0$45946$a344fe98@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

>
>
>


Marrow 10-21-2004 11:17 PM

Re: XPath copying all nodes that are not in a namespace
 
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" <tjerk@wolterinkwebdesign.com> wrote in message
news:41781478$0$61769$abc4f4c3@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" <tjerk@wolterinkwebdesign.com> wrote in message
> > news:4177d0ff$0$45946$a344fe98@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

> >
> >
> >





All times are GMT. The time now is 03:48 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.