You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christian Schlichtherle <ch...@schlichtherle.de> on 2007/05/31 17:20:29 UTC

How to suppress xmlns:jx attribute in output of JXTemplate generator?

Hi,

I have an XSL stylesheet which needs to be preprocessed with JXTemplate so
that the resulting sheet strictly conforms to XSL 1.0 (so it can be
processed by some recent browsers).

The stylesheet looks like this:

<xsl:stylesheet version="1.0"
                xmlns=" <http://www.w3.org/1999/xhtml>
http://www.w3.org/1999/xhtml"
                xmlns:xsl=" <http://www.w3.org/1999/XSL/Transform>
http://www.w3.org/1999/XSL/Transform"
                xmlns:jx=" <http://apache.org/cocoon/templates/jx/1.0>
http://apache.org/cocoon/templates/jx/1.0"
                exclude-result-prefixes="jx">
    <!-- Parameter declaration. -->
    <jx:choose>
        <jx:when test="${empty(cocoon.request.select)}">
            <xsl:param name="select">start</xsl:param>
        </jx:when>
        <jx:otherwise>
            <xsl:param name="select">${cocoon.request.select}</xsl:param>
        </jx:otherwise>
    </jx:choose>
    <!-- remainder omitted -->
</xsl:stylesheet>

Now if I preprocess it like this:

            <map:match pattern="*.xsl">
                <map:generate label="style" type="jx" src="{0}"/>
                <map:serialize type="xml"/>
            </map:match>

... then the resulting output still contains the xmlns:jx attribute in the
<xsl:stylesheet> tag:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE stylesheet>
<xsl:stylesheet xmlns=" <http://www.w3.org/1999/xhtml>
http://www.w3.org/1999/xhtml"
    xmlns:xsl=" <http://www.w3.org/1999/XSL/Transform>
http://www.w3.org/1999/XSL/Transform"
    xmlns:jx=" <http://apache.org/cocoon/templates/jx/1.0>
http://apache.org/cocoon/templates/jx/1.0"
    version="1.0"
    exclude-result-prefixes="jx">
   <xsl:param name="select">start</xsl:param>
   <!-- remainder omitted -->
</xsl:stylesheet>

This should not be necessary since all <jx:tag>s have been processed and
removed from the output.

Any clues how I can remove them easily (without writing another XSL
stylesheet hopefully)?

Kind regards,
Christian Schlichtherle
--
Schlichtherle IT Services
Wittelsbacherstr. 10a
10707 Berlin

Tel: +49 (0) 30 / 34 35 29 29
Mobil: +49 (0) 173 / 27 12 470
 <ma...@schlichtherle.de> mailto:christian@schlichtherle.de <
<ma...@schlichtherle.de> mailto:christian@schlichtherle.de>
 <http://www.schlichtherle.de> http://www.schlichtherle.de <
<http://www.schlichtherle.de/> http://www.schlichtherle.de/>



RE: How to suppress xmlns:jx attribute in output of JXTemplate generator?

Posted by Christian Schlichtherle <ch...@schlichtherle.de>.
Hi Giuseppe,

thank you for your information.

Kind regards,
Christian

RE: How to suppress xmlns:jx attribute in output of JXTemplate generator?

Posted by Christian Schlichtherle <ch...@schlichtherle.de>.
Hi,

based on your script, this is what I derived:

<?xml version="1.0" encoding="UTF-8" ?>
<!-- Strips unused XML namespace declarations from the result tree. -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="*">
        <xsl:element name="{name()}">
            <xsl:apply-templates select="@*"/>
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="@*">
        <xsl:copy/>
    </xsl:template>
</xsl:stylesheet>

The difference to the script provided by you is that this one only removes
namespaces if they are not used by an element. So the resulting XML is
remains valid.

Thank you very much again for setting me on the right track.

Kind regards,
Christian

Re: How to suppress xmlns:jx attribute in output of JXTemplate generator?

Posted by Giuseppe Di Pierri <gi...@gmail.com>.
On 31/05/07, Giuseppe Di Pierri <gi...@gmail.com> wrote:
> On 31/05/07, Christian Schlichtherle <ch...@schlichtherle.de> wrote:
> >
> >
> >
> > Hi,
> >
> > I have an XSL stylesheet which needs to be preprocessed with JXTemplate so
> > that the resulting sheet strictly conforms to XSL 1.0 (so it can be
> > processed by some recent browsers).
> >
> > The stylesheet looks like this:
> >
> > <xsl:stylesheet version="1.0"
> >                 xmlns="http://www.w3.org/1999/xhtml"
> >
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >
> > xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
> >                 exclude-result-prefixes="jx">
> >     <!-- Parameter declaration. -->
> >     <jx:choose>
> >         <jx:when test="${empty(cocoon.request.select)}">
> >             <xsl:param name="select">start</xsl:param>
> >         </jx:when>
> >         <jx:otherwise>
> >             <xsl:param name="select">${cocoon.request.select}</xsl:param>
> >         </jx:otherwise>
> >     </jx:choose>
> >     <!-- remainder omitted -->
> > </xsl:stylesheet>
> >
> > Now if I preprocess it like this:
> >
> >             <map:match pattern="*.xsl">
> >                 <map:generate label="style" type="jx" src="{0}"/>
> >                 <map:serialize type="xml"/>
> >             </map:match>
> >
> > ... then the resulting output still contains the xmlns:jx attribute in the
> > <xsl:stylesheet> tag:
> >
> > <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE stylesheet>
> > <xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml"
> >     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >     xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
> >     version="1.0"
> >     exclude-result-prefixes="jx">
> >    <xsl:param name="select">start</xsl:param>
> >    <!-- remainder omitted -->
> > </xsl:stylesheet>
> >
> > This should not be necessary since all <jx:tag>s have been processed and
> > removed from the output.
> >
> > Any clues how I can remove them easily (without writing another XSL
> > stylesheet hopefully)?
> >
>
> If you don't mind using xsl, we adopt something like this in order to
> get xhtml namespace only (don't forget to replace the namespace of
> xhtml with xsl one - http://www.w3.org/1999/XSL/Transform - and maybe
> you don't need to translate text()):
>

Errata Corrige:
you would suppress the jx (http://apache.org/cocoon/templates/jx/1.0)
and not the xsl :-)

> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xml:space="default">
>         <xsl:template match="/">
>                 <xsl:apply-templates />
>         </xsl:template>
>
>         <xsl:template match="text()">
>                 <xsl:value-of select="translate(.,'&#9;&#10;&#13;','   ')" />
>         </xsl:template>
>
>         <xsl:template match="*">
>                 <!-- remove element prefix (if any) -->
>                 <xsl:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml">
>                         <xsl:apply-templates select="@*" />
>                         <xsl:apply-templates />
>                 </xsl:element>
>         </xsl:template>
>
>         <xsl:template match="@*">
>                 <xsl:attribute name="{local-name()}">
>                         <xsl:value-of select="." />
>                 </xsl:attribute>
>         </xsl:template>
>
>
>         <xsl:template match="comment()">
>                 <xsl:copy />
>         </xsl:template>
>
> </xsl:stylesheet>
>
> Good luck with dynamic xsl ;-)
>
> bye
>
> pino
>
>
> --
> Giuseppe Di Pierri
> Managing Director
> ______________________
> Phiware Engineering Sagl
> via Ginevra 5
> CH-6900 Lugano
> Tel. +41 91 260 75 55
> Fax.+41 91 260 75 59
> Email. giuseppe.dipierri@phiware.ch
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: How to suppress xmlns:jx attribute in output of JXTemplate generator?

Posted by Giuseppe Di Pierri <gi...@gmail.com>.
On 31/05/07, Christian Schlichtherle <ch...@schlichtherle.de> wrote:
>
>
>
> Hi,
>
> I have an XSL stylesheet which needs to be preprocessed with JXTemplate so
> that the resulting sheet strictly conforms to XSL 1.0 (so it can be
> processed by some recent browsers).
>
> The stylesheet looks like this:
>
> <xsl:stylesheet version="1.0"
>                 xmlns="http://www.w3.org/1999/xhtml"
>
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
> xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
>                 exclude-result-prefixes="jx">
>     <!-- Parameter declaration. -->
>     <jx:choose>
>         <jx:when test="${empty(cocoon.request.select)}">
>             <xsl:param name="select">start</xsl:param>
>         </jx:when>
>         <jx:otherwise>
>             <xsl:param name="select">${cocoon.request.select}</xsl:param>
>         </jx:otherwise>
>     </jx:choose>
>     <!-- remainder omitted -->
> </xsl:stylesheet>
>
> Now if I preprocess it like this:
>
>             <map:match pattern="*.xsl">
>                 <map:generate label="style" type="jx" src="{0}"/>
>                 <map:serialize type="xml"/>
>             </map:match>
>
> ... then the resulting output still contains the xmlns:jx attribute in the
> <xsl:stylesheet> tag:
>
> <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE stylesheet>
> <xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml"
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>     xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
>     version="1.0"
>     exclude-result-prefixes="jx">
>    <xsl:param name="select">start</xsl:param>
>    <!-- remainder omitted -->
> </xsl:stylesheet>
>
> This should not be necessary since all <jx:tag>s have been processed and
> removed from the output.
>
> Any clues how I can remove them easily (without writing another XSL
> stylesheet hopefully)?
>

If you don't mind using xsl, we adopt something like this in order to
get xhtml namespace only (don't forget to replace the namespace of
xhtml with xsl one - http://www.w3.org/1999/XSL/Transform - and maybe
you don't need to translate text()):

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xml:space="default">
	<xsl:template match="/">
		<xsl:apply-templates />
	</xsl:template>

	<xsl:template match="text()">
		<xsl:value-of select="translate(.,'&#9;&#10;&#13;','   ')" />
	</xsl:template>

	<xsl:template match="*">
		<!-- remove element prefix (if any) -->
		<xsl:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml">
			<xsl:apply-templates select="@*" />
			<xsl:apply-templates />
		</xsl:element>
	</xsl:template>

	<xsl:template match="@*">
		<xsl:attribute name="{local-name()}">
			<xsl:value-of select="." />
		</xsl:attribute>
	</xsl:template>


	<xsl:template match="comment()">
		<xsl:copy />
	</xsl:template>

</xsl:stylesheet>

Good luck with dynamic xsl ;-)

bye

pino


-- 
Giuseppe Di Pierri
Managing Director
______________________
Phiware Engineering Sagl
via Ginevra 5
CH-6900 Lugano
Tel. +41 91 260 75 55
Fax.+41 91 260 75 59
Email. giuseppe.dipierri@phiware.ch

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org