[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] namespace aware template matching
Subject: [xsl] namespace aware template matching From: tom.kirkpatrick@xxxxxxxxxxxx Date: Thu, 27 Oct 2005 09:03:18 +0100 |
I'm trying to do some rather complicated, namespace aware XPath (XSLT1) template matching: Given a structure like this, where <dynamic> could actually be any number (including 0) of elements in a namespace other than 'uri://ns-namespace': <ns:root xmlns:ns="uri://ns-namespace"> <ns:id> id from ns:root/ns:id </ns:id> <dynamic> <ns:article> <dynamic> <ns:id> id from ns:root/ns:article/ns:id </ns:id> </dynamic> </ns:article> <ns:issue> <dynamic> <more tags> <ns:id> id from ns:root/ns:issue/ns:id </ns:id> </more tags> </dynamic> </ns:issue> </dynamic> </ns:root> I need a template which matches all <ns:id> elements whoose path from the <ns:root> node is simply 'ns:root/ns:article/ns:id'. So I need to be able o exclude all elements from any namespace which is not 'ns'. What I mean is something like this: (although it doesn't work!) <xsl:template match="ns:root/*[namespace-uri() != 'uri://ns-namespace']/ns:article/*[namespace-uri() != 'uri://ns-namespace']/ns:id"/> </xsl:template> But this doesn't match the case where there are no foreign elements (whose namespace is not 'ns') or more than one foreign element in between ns:root and ns:article or between ns:article and ns:id. The clocest I came was: <xsl:template match="ns:id[ancestor::ns:article/ancestor::ns:root]"/> But this one doesn't stipulate that the ancestor::ns:article who has an ancestor::ns:root must be the first 'ns' ancestor we meet, so It will also match: <ns:root xmlns:ns="uri://ns-namespace"> <ns:id> id from ns:root/ns:id </ns:id> <dynamic> <ns:test> <ns:article> <ns:test2> <dynamic> <ns:id> id from ns:root/ns:test/ns:article/ns:test2/ns:id </ns:id> How can I specify that the ancestor::ns:article element must be the first one we come accross when working up the acnestor chain? any thoughts? thanks -- Tom Kirkpatrick Web Developer - Virus Bulletin
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Embedded Stylesheets + doc() , David Riggs | Thread | Re: [xsl] namespace aware template , tom . kirkpatrick |
Re: [xsl] foreach, preceding-siblin, Mingqiang Yu | Date | Re: [xsl] namespace aware template , tom . kirkpatrick |
Month |
Keywords