|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Hi there.
I just wonder if there's a way to manage identical tags in XML source(s) with different XSL templates. Just to be clear, an example: .... <space1:body> <ciccio>Bla bla</ciccio> </space1:body> <space2:body> <ciccio>1243</ciccio> </space2:body> .... I'd like to be able to manage the two <ciccio> with a template depending on their parent's namespace. I tried this in my XSL sheet: .... <xsl:template match="space1:ciccio"> ciccio is a nice guy </xsl:template> <xsl:template match="space2:ciccio"> ciccio is a number </xsl:template> ..... but it doesn't seem to match. Anybody there knows how to do this? Thanx since now. |
|
#2
|
|||
|
|||
|
Neither ciccio appear to have a namespace defined for them, which means they are taking any default namespace defined in the document. I think to achieve what you want you will need to do something like this:
Code:
<space1:body>
<space1:ciccio>Bla bla</space1:ciccio>
</space1:body>
<space2:body>
<space2:ciccio>1243</space2:ciccio>
</space2:body>
|
|
#3
|
||||
|
||||
|
Quote:
I tried this, but it revealed to be not useful to me. Declaring explicitely <space1:ciccio> or <space2:ciccio> it's exactly like declaring <ciccio1> or <ciccio2>, like declaring two different tags. I'd need to know a way, if it exists, to put the same tag in different point of my XML document (namespaces?) and have those processed back in two different ways. I initially hoped that namespace declaration was inheritable (see my previous post in this thread); this could have permitted to simply declare the same <ciccio> tag under different tags with respective explicit namespace assignment. But it doesn't seem to work. But neither this way you propose seem to be useful to me ![]() Thank you anyway. ![]() |
|
#4
|
|||
|
|||
|
You have to explicitly state the namespace for every element other than those for which a default namespace has been set (either in the root or at an element level).
I think the problem lies with how you are processing your XML file, or how you are transforming it (XSLT). I think we need more info. |
|
#5
|
||||
|
||||
|
Trying to build an effective example:
Suppose I have to render a login form on a web site. It could be rendered in a menu on the page side or sometimes in the page main body. Both are described with the same XML (suppose tag <login>....</login>) but not rendered by the same XSLT. I intended to define a 'body' namespace and a 'menu' namespace. Whenever the XSLT processor finds a <login> tag it calls a different template depending on the namespace the <login> falls within. Now I'm starting thinking another way: I could define templates matching the "body/login" pattern and another one matching "menu/login". This would permit me to render two different login forms called by the same <login> tag in two different contexts, isn'it? Bye again. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Namespace inheritance and XSLT |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|