Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSL namespace question

 
Jun Hong
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question about how to handle namespaces in XML and XSLT. If I have namespaces in XML what will happen to XSLT?
Say if I have xml looks like this:
<?xml version="1.0"?>
<?CMFToolkit version="v4.9"?>
<InstrumentMessageContainer xmlns="com.ubs.cmf.cmm.v2_1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="I1">
<dataContainer xsi:type="InstrumentDataContainer" id="I2">
How can I handle xmlns and xsi. Say if I want to write a template which will take those attributes in InstrumentMessageContainer tag and put it into result xml, what should I do?
I tried this and it doesn't work.
<xsl:template match="/">
<xsl:apply-templates select="InstrumentMessageContainer"/>
</xsl:template>

<xsl:template match="InstrumentMessageContainer">
<InstrumentMessageContainer xmlns:xsi="{@xmlns:xsi}">
<xsl:apply-templates select="dataContainer"/>
</InstrumentMessageContainer>
</xsl:template>
If somebody know this, please help.
[ May 08, 2002: Message edited by: Jun Hong ]
 
Neetha Kasuganti
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to include a corresponding namespace declaration in your stylesheet, binding it to a prefix of your choice. Then, in your match patterns, include that prefix.
try with this stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:j="com.ubs.cmf.cmm.v2_1" (prefix must be used in the namespace declaration)version="1.0">
<xsl:template match="/">
<xsl:apply-templates select="j:InstrumentMessageContainer" /> (all the elements that are accessed by the xsl processor must be prefixed)
</xsl:template>
<xsl:template match="j:InstrumentMessageContainer">
<InstrumentMessageContainer xmlns:xsi="{@xmlns:xsi}">
<xsl:apply-templates select="j: DataContainer"/>
</InstrumentMessageContainer>
</xsl:template>
reference: http://www.dpawson.co.uk/xsl/sect2/N5536.html#d163e420
[ May 08, 2002: Message edited by: Neetha Kasuganti ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic