• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

XSL namespace question

 
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 ]
 
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 ]
 
rubbery bacon. rubbery tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!