xsl-list
[Top] [All Lists]

Re: matching attribute values with namespaces

2005-07-12 14:02:33
Stefan Podkowinski wrote:
I'm currently having a hard time to create a xsl definition for the
following situation:

<document
   xmlns:providerns1="http://somewhere.com/";
   xmlns:providerns2="http://sometimes.com/";>
<entry type="providerns1:header">test</entry>
<entry type="providerns1:paragraph">test</entry>
<entry type="providerns2:paragraph">test</entry>
<entry type="providerns2:footer">test</entry>
</document>

What I basically need to do is to check to which namespace each "type"
attribute value belongs to. Afterwards I'm able to go on to transform
the entry element depending on the type value for the determinated
namespace.

Check out §5.4 of XPath 1.0.  A namespace node?s name is its prefix, and
its value is the URI.

<xsl:template match="document">
  <!-- This will be the providerns1 namespace node. -->
  <xsl:variable name="ns1"
    select="namespace::*[. = 'http://somewhere.com/']"/>
  <xsl:apply-templates
    select="entry[contains(@type, name($ns1))]"/>
</xsl:template>

That template should process only the entry elements whose type contains
the prefix bound to ?http://somewhere.com/?.  (The contains() expression
should actually be more complex than that to avoid inadvertent substring
matches.)

That also won?t work if the entry elements themselves define any relevant
namespaces themselves.  So don?t do that. (-:

~Chris
-- 
Christopher R. Maden, Principal Consultant, crism consulting
XML-SGML-HTML-DTDs-schemas-XSL-DSSSL-conversion-training-ebooks-B2B
<URL: http://crism.maden.org/consulting/ >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4  5DFC AC52 F825 AFEC 58DA


--~------------------------------------------------------------------
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>