xsl-list
[Top] [All Lists]

RE: [xsl] Mapping via intermediate XML file problem

2008-04-01 06:48:34
The most likely explanation is that your source document contains an element
name which is not present in the mapping document. It should be easy enough
to write your code to guard against this possibility, perhaps outputting an
xsl:message and using the existing tag name when it happens. 

Are you sure it makes sense to do

<xsl:apply-templates select="node()|@*"/>?

Applying templates to attribute nodes, when there is no template rule that
matches attributes, does not seem a very good idea. However, I don't think
this is the cause of your problem.

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

-----Original Message-----
From: Lech Rzedzicki [mailto:xchaotic(_at_)gmail(_dot_)com] 
Sent: 01 April 2008 21:42
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Mapping via intermediate XML file problem

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[(_at_)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.

Any pointers deeply appreciated,

Lech

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>