OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   RE: [xml-dev] Xml to xml transformation

[ Lists Home | Date Index | Thread Index ]

XSLT coding questions are generally best asked on the xsl-list at

Your transformation doesn't produce "no output", it produces this:

<sample xmlns:tm="urn:xmlintl-tm-tags" tm:tm="">
Sample para. This needs to be translated
This is not translated
This is not translated</sample>

Note that it's not a good idea to use the browser as an XSLT development
platform - diagnostics are hopelessly poor. Use a free-standing development
tool like Stylus Studio, Oxygen, or XML Spy, or simply a command-line XSLT

I suspect that this instruction:

<xsl:attribute name="xmlns:tm" namespace="urn:xmlintl-tm-tags"/>

was attempting to produce a namespace declaration. Namespaces and attributes
are quite different things in the XSLT/XPath data model, and xsl:attribute
never creates a namespace node. In fact, this instruction ignores the
"xmlns:" prefix, and produces an attribute with local-name "tm" in the
namespace "urn:xmlintl-tm-tags". You don't need to generate the namespace
declaration by hand, because a literal result element (<select>)
automatically gets copies of all the namespaces that are in-scope in the
stylesheet, unless you take steps to exclude them. So the result document
already has a namespace binding for xmlns:tm="urn:xmlintl-tm-tags", which is
why Saxon chose to name the attribute "tm:tm".

This instruction:

<xsl:apply-templates select="//test" mode="tm:ta"/>

searches for a template rule such as

<xsl:template match="test" mode="tm:ta">

There isn't one, so it uses the built-in template, which simply displays the
textual content of the element. You don't need modes here, so just get rid
of the mode attribute.

It would also be better to use an explicit path: select="sample/test" rather
than select="//test" which involves a whole-document search.

This construct:

<xsl:element name="tm:ta">
<xsl:attribute name="name">

could be more economically written as:

<tm:ta name="trans_attr"/>

Michael Kay

> I have source xml like this:
> <?xml version="1.0" encoding="UTF-8"?>
> <sample>
> <test trans_attr="trans">
> <para>Sample para. This needs to be translated</para>
> <comments>This is not translated</comments>
> </test>
> </sample>
> Need output xml as:
> <?xml version="1.0" encoding="UTF-8"?>
> <sample xmlns:tm="urn:xmlintl-tm-tags">
> <test trans_attr="trans">
> <tm:ta id="a1" name="trans_attr">
>        <src>trans</src>
>        <tgt></tgt>
>     </tm:ta>
> <para>Sample para. This needs to be translated</para>
> <tm:nxlt><comments>This is not translated</comments></tm:nxlt>
> </test>
> </sample>
> How will I do it with xslt, done some stupid showing no 
> output on browser.
> Xslt:
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> xmlns:tm="urn:xmlintl-tm-tags">
> 	<xsl:output method="xml" version="1.0" encoding="UTF-8"
> indent="yes"/>
> <xsl:template match="/">
> <sample>
> <xsl:attribute name="xmlns:tm" namespace="urn:xmlintl-tm-tags"/>
> <xsl:apply-templates select="//test" mode="tm:ta"/>
> <xsl:apply-templates select="//comments" mode="tm:nxlt"/>
> </sample>
> </xsl:template>
> <xsl:template match="test">
> <xsl:element name="tm:ta">
> <xsl:attribute name="name">
> <xsl:text>trans_attr</xsl:text> 
> </xsl:attribute> 
> </xsl:element>
> <xsl:element name="src">
> <xsl:value-of select="@trans_attr"/>
> </xsl:element>
> <xsl:element name="tgt"/>
> </xsl:template>
> <xsl:template match="comments">
> <xsl:element name="tm:nxlt">
> </xsl:element>
> </xsl:template>
> </xsl:stylesheet>
> Can anyone help me out?
> Thanks,
> Shailesh
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> The list archives are at http://lists.xml.org/archives/xml-dev/
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://www.oasis-open.org/mlmanage/index.php>


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS