[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] NEWBIE query re Polymorphic stylesheets


Subject: [xsl] NEWBIE query re Polymorphic stylesheets
From: gerry.king@xxxxxxxxxxxxxxxxxx
Date: Thu, 22 Aug 2002 11:57:20 +0100

Last week I spent  two days trying to figure this out searching the web,
Doug Tidwell's XSLT  (ORA)  and dpawson's FAQ on Namespaces before posting
this question - hopefully this time someone can answer yea or nay...

I want to write a stylesheet that will handle XML that comes in with and
without the 'header'.

<?xml version="1.0" encoding="UTF-8"?>
<RII>
  <Invoices>
    ......
and

<?xml version="1.0" encoding="UTF-8"?>
<RII version="1.0" xmlns="http://www.regent-inns.com/RegentInvoices.xsd"
xmlns:mstns="http://www.regent-inns.com/XMLSchema.xsd" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.regent-inns.com/RegentInvoices.xsd C:\AIP\RIInvoice.XSD">
  <Invoices>
    ......

How do I write a  stylesheet without  having two versions of everything -
one without namespace prefixes and the other with? At present my code
duplicates everything:


<xsl:template match="Invoice">
  <!-- Works for files without namespace -->
    <Invoice>
      <SuppAcctCode>
           <xsl:value-of select="AcctCode"/>
      </SuppAcctCode>
      ....

<xsl:template match="RII:Invoice">
  <!-- Works for files with namespace -->
      <SuppAcctCode>
        <xsl:value-of select="RII:AcctCode"/>
      </SuppAcctCode>
        ....


I have looked at namespace-alias and local-name but can't see how they
would help.  Should I set a variable 'namespace'  and use that as a prefix?
How?

TIA

Gerry King



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords