Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Mapping via intermediate XML file problem

From: Wendell Piez <wapiez@---------------->
To:
Date: 4/1/2008 2:40:00 PM
Lech,



Since you are using XSLT 2.0, you can fall back to the actual name in 
the same XPath you use to look up a new name:



<xsl:element name="{($maps[@old = 
local-name(current())]/@new),local-name())[1]}">



This uses the idiom ($a, $b)[1] whereby the first item in $b is used 
when $a is empty.



If you want to generate a warning message, this is done easily with a 
conditional:



<xsl:if test="empty($maps[@old = local-name(current())]/@new)">
  ... generate your message ...
</xsl:if>

(A stricter test would check if your mapped name were a valid Qname, 
just in case.)



I hope this helps,
Wendell


At 09:41 AM 4/1/2008, you wrote:
Hi.



I'm doing a simple transformation, substituting some tags with
different named ones and keeping the rest the same.
Since there are many strange cases, I'd like to keep the mapping in
the intermediate XML file (to keep the XSL clean), such as maps.xml:

<?xml version="1.0" encoding="UTF-8"?>
<maps>
    <map old="old-tag1" new="tag1"></map>
    <map old="old-strange-tag2" new="tag2"></map>
    <!-- <map old="" new=""></map> -->
</maps>

and then transform using:



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="2.0">



<xsl:variable name="maps" 
select="document('maps.xml')/maps/map"></xsl:variable>



<xsl:template match="*">
    <xsl:element name="{$maps[@old = local-name(current())]/@new}">
        <xsl:apply-templates select="node()|@*"/>
    </xsl:element>
</xsl:template>

</xsl:stylesheet>



But when I run that through Saxon 9B it says "Invalid element name.
Invalid QName {}" URL: http://www.w3.org/TR/xslt20/#err-XTDE0820

My source file contains both the elements matched by map and other 
elements too.




======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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