XSL and namespaces

This may be a very simple question, but I seem to be unable to get it, and I will tear my hair apart. I have the following XML:

<?xml-stylesheet type="text/xsl" href="email.xsl"?> <Example xmlns=""> <Name xmlns="urn:rnb.fulfilment.bus.contracts.public.exampleBookName.v1">Mark</Name> </Example> 

And I'm trying to use the following XSLT:

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:template match="/"> <html> <body> <table width="90%" border="0" cellpadding="0" cellspacing="0"> <tr> <td> <p>AUTOMATED CONFIRMATION: This confirmation email is unable to take replies. For further assistance please visit our Help pages or Contact us</p> <p>Dear <xsl:value-of select="Name"/>,</p> <p>Thank you for blah blah... </p> </td> </tr> </table> <xsl:apply-templates/> </body> </html> </xsl:template> </xsl:stylesheet> 

I cannot get the name that will be displayed when I use xmlns=urn:rnb.fulfilment.bus.contracts.public.exampleBookName.v1 in the XML feed, when I delete xmlns , the name is displayed normally.

Is there any syntax that I am missing? I tried adding a namespace to the <xsl:stylesheet> element:

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rpg="urn:rnb.fulfilment.bus.contracts.public.exampleBookName.v1" > 

Then, using the prefix I gave XSLT in the XPath expression:

 <xsl:value-of select="Name"/> 

But that will not work either. Can anyone help? Thanks in advance.

+4
source share
3 answers

Alternatively, use the predicate and local-name (). For instance:.

 <xsl:value-of select="*[local-name() = 'Name']"/> 
0
source

Your namespace declaration approach in <xsl:stylesheet> already correct. Now all you have to do is also use the prefix:

 <xsl:value-of select="Example/rpg:Name" /> 

I also recommend making a small change to your template to better reflect your input:

 <xsl:template match="Example"> <!-- ... --> <xsl:value-of select="rpg:Name" /> </xsl:template> 
+6
source

You need to use the same namespace in XSLT to match the XPath expression for Name .

 <xsl:value-of select="x:Name" xmlns:x="urn:rnb.fulfilment.bus.contracts.public.exampleBookName.v1"/> 
+4
source

Source: https://habr.com/ru/post/1306130/


All Articles