Subject: Re: [xsl] Matching attributes with namespace|
From: "Spencer Tickner" <spencertickner@xxxxxxxxx>
Date: Thu, 3 Aug 2006 10:31:51 -0800
Thanks for the responses. It's just a day before vacation and I was hoping to avoid wading through someone else's Perl code. But I can see that this is probably unavoidable. Thanks for the responses.
I'm not sure what you mean by the attributes on the act element getting jumbled. (Maybe I've been looking at the screen too long. :-) The only difference I see between your input and output is that the order of the attributes is different. While from the point of view of the instance-considered-as-text-file this reordering may constitute a jumbling, from the point of view of the instance-considered-as-XML-document, it doesn't, as attribute ordering is not considered to be semantically significant in XML, and no XML processor or parser is bound to respect it.
If this is the source of your troubles, you basically have three options:
1. Try different XSLT engines until you find one that happens to respect your attribute ordering, and then use that one. (Meanwhile document the requirement, as it's over and above simple XML and XSLT.)
2. Try providing a template in your stylesheet that explicitly forces the processing order of these attributes (oops: except one is a namespace declaration, ouch!), and see if that helps. It might or might not. Again, be aware that since your requirement for a particular attribute ordering is over and above XML semantics, if this works it's just a case of your being lucky.
3. Fix the other process(es) that expect a particular attribute ordering so they're actually XML-compliant.
I'd personally go for option 3, as both "correct" and most likely to make the headache go away permanently.
I hope that helps, Wendell
At 02:08 PM 8/3/2006, you wrote: >Hi List, > >Thanks in advance for the help. I have a very simple transformation >that I can't seem to get right. The following is a shortened example. > >XML > ><?xml version="1.0"?> ><?xml-stylesheet type="text/xsl" href="../../media/xslt_2.xsl"?> ><act xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >xsi:noNamespaceSchemaLocation="../../media/ActSchema.xsd" >index="96001_01"> > <title>This is the <insert>title</insert></title> ></act> > > >XSL > ><?xml version='1.0'?> ><xsl:stylesheet version="2.0" >xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > ><xsl:template match="/"> > <xsl:apply-templates/> ></xsl:template> > > <xsl:template match="node()"> > <xsl:copy> > <xsl:copy-of select="@*" /> > <xsl:apply-templates select="node()" /> > </xsl:copy> > </xsl:template> > > ><xsl:template match="insert"><xsl:apply-templates/></xsl:template> > ></xsl:stylesheet> > > >So basically just stripping out the insert element. Everything else >should stay the same. However my attributes on <act> get jumbled to: > >OUTPUT > ><?xml version='1.0' ?> ><?xml-stylesheet type="text/xsl" href="../../media/xslt_2.xsl"?> ><act index="96001_01" >xsi:noNamespaceSchemaLocation="../../media/ActSchema.xsd" >xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> > <title>This is the title</title> ></act> > >and for whatever reason this is messing up other things in our >work-flow. Anyone have any ideas on how to make the <act> attributes >come out exactly as they are in the source document? > >Thanks, > >Spencer