Subject: [xsl] NAMESPACES - Part 2 of (Moving an element to a new location in the Result-tree) From: "Graves, Jim \(CONTR\)" <jim.graves@xxxxxxx> Date: Fri, 9 Sep 2005 20:30:04 -0700 |
This is a follow-on question related to my earlier one about: "Moving an element to a new location in the Result-tree." (my new QUESTION is stated below) -- (And thanks for your prior help!!) Please Cc: my home e-mail, so I can see your reply from home this weekend?) 'swguild@xxxxxxxxxxxxxx' Essentially I have two version of input data one with and one without namespaces, so my XSLT works on the latter, not former (the namespaces are causing problems). My 'toy version' of the input data file works just fine w.r.t. its intent, namely creating a new file (containing the newly formed 'result-tree') in which the <INDIVIDUAL_ALIAS> elements have been 'herded down,' to their new home in the tree, (as I refer to moving my 'data elephants' sometimes) (;>} (Forgive my levity, but it's Friday night -- and I should be home by now). However, now I have to resolve why my XSLT, shown below, is processing differently on the files that only differ with respect to the presence or absence of namespaces: (I'm using XMLSpy version 2005 release 3 (for development/debugging), of Ent. Edn. and the (nearly latest) .NET XSLT 1.1, but not 2.0, (it's used for production) -- (BTW, how can I get XSLT 2.0 in there, if it's possible?)). As I see it, when debugging down through the code in XMLSpy, without the namespaces, everything flows perfectly and life is good, (:>}. Then, when I introduce the 'real data,' with namespaces and prefixes, etc, the XSLT process chooses to follow a different sequence; see data versions. Specifically, it avoids my template named "Transfer" (-- apparently disregarding the 'optional' priority value): (without the namespaces in the data, it uses this template and all is well). <xsl:template match="Transfer" priority="5.0"> <Transfer> <IND> <xsl:apply-templates select="IND"/> </IND> </Transfer> and then consumes the entire file with the 'node-eater' (via <xsl:copy): <xsl:template match="@*|node()" > <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> In this case, having the disastrous result of omitting my key template: (the 'Good Shepard template' ("IND") who herds my data elephants down the tree..) <xsl:template match="IND" priority="4.0"> <xsl:apply-templates select="*[not(self::INDIVIDUAL_ALIAS)]"/> <xsl:apply-templates select="INDIVIDUAL_ALIAS" /> </xsl:template> Without this execution, I fail to obtain my desired result and life is bad. MY QUESTION: since I need to have these (and several other namespaces/prefixes, such as: xmlns:ABC="http://www.abc.xyz.pdq/ABC" and several others (must haves)), so then, what can I do to mitigate the effect of their presence in the input data tree? This problem happens immediately, prior to when it gets to my first element, since it's not shown as highlighted in XMLSpy, if namespaces are present, yet if they are not present, then the tag is highlighted and all flows well). (Something happening behind the scenes in the XSLT process (what?). Again: "<Transfer>" (is OK), however, "<Transfer xmlns:xs="http://www.w3.org/2001/XMLSchema" (is not OK; skips the special template, "IND"). INPUT DATA Less Complex Input (without namespaces): <Transfer> <IND> <NAME_LAST>PEITER</NAME_LAST> <NAME_FIRST>ED</NAME_FIRST> <NAME_MIDDLE>WARECO</NAME_MIDDLE> <INDIVIDUAL_ALIAS> <IND_ALIAS_TYPE>UNKNOWN</IND_ALIAS_TYPE> <Name>DASTEFANO,ALEX</Name> </INDIVIDUAL_ALIAS> <INDIVIDUAL_ALIAS> <IND_ALIAS_TYPE>UNKNOWN</IND_ALIAS_TYPE> <Name>PURSA, NILLIAM, JR</Name> </INDIVIDUAL_ALIAS> <BIRTH_DATE>19510515</BIRTH_DATE> <GENDER>M</GENDER> <IND_HEIGHT>67"</IND_HEIGHT> <IND_WEIGHT>150</IND_WEIGHT> <EYE_COLOR>Brown</EYE_COLOR> <HAIR_COLOR>Brown</HAIR_COLOR> </IND> </Transfer> More Complex Input (with namespaces, causing problems): <Transfer xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes"> <IND> NAME_LAST>PEITER</NAME_LAST> <NAME_FIRST>ED</NAME_FIRST> <NAME_MIDDLE>WARECO</NAME_MIDDLE> <INDIVIDUAL_ALIAS> <IND_ALIAS_TYPE>UNKNOWN</IND_ALIAS_TYPE> <Name>DASTEFANO,ALEX</Name> </INDIVIDUAL_ALIAS> <INDIVIDUAL_ALIAS> <IND_ALIAS_TYPE>UNKNOWN</IND_ALIAS_TYPE> <Name>PURSA, NILLIAM, JR</Name> </INDIVIDUAL_ALIAS> <BIRTH_DATE>19510515</BIRTH_DATE> <GENDER>M</GENDER> <IND_HEIGHT>67"</IND_HEIGHT> <IND_WEIGHT>150</IND_WEIGHT> <EYE_COLOR>Brown</EYE_COLOR> <HAIR_COLOR>Brown</HAIR_COLOR> </IND> </Transfer> XSLT: <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output version="1.0" method="xml" omit-xml-declaration="no" encoding="UTF-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> <xsl:copy> <xsl:apply-templates select="*"/> </xsl:copy> </xsl:template> <xsl:template match="Transfer" priority="5.0"> <Transfer> <IND> <xsl:apply-templates select="IND"/> </IND> </Transfer> </xsl:template> <xsl:template match="IND" priority="4.0"> <xsl:apply-templates select="*[not(self::INDIVIDUAL_ALIAS)]"/> <xsl:apply-templates select="INDIVIDUAL_ALIAS" /> </xsl:template> <xsl:template match="@*|node()" > <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSL/Cocoon debugger, J.Pietschmann | Thread | Re: [xsl] NAMESPACES - Part 2 of (M, Mukul Gandhi |
[xsl] XSL/Cocoon debugger, Oleg Konovalov | Date | Re: [xsl] NAMESPACES - Part 2 of (M, Mukul Gandhi |
Month |