Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xml-dev] Xml to xml transformation

From: "Michael Kay" <mike@--------.--->
To: "'Shailesh'" <shailesh@--------.--->,<xml-dev@-----.---.--->
Date: 8/3/2005 8:34:00 AM
XSLT coding questions are generally best asked on the xsl-list at
mulberrytech.com

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 XMLSpy">XMLSpy, or simply a command-line XSLT
processor.

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">
<xsl:text>trans_attr</xsl:text> 
</xsl:attribute> 
</xsl:element>

could be more economically written as:

<tm:ta name="trans_attr"/>

Michael Kay
http://www.saxonica.com/

> 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>
> 
>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent