xslt - How to remove names from the non-empty namespaces they belong to? -


i want transform input xml file using xslt change name of particular element can appear @ different places of xml tree.

i have xml following,

 <catalog>  <cd>   <ost:title>empire burlesque</ost:title>   <artist>bob dylan</artist>   <country>usa</country>   <company>      <ost:name>columbia<ost:name>   </company>   <price>10.90</price>   <year>1985</year>  </cd> </catalog> 

i want remove 'ost:' prefix elements , keep else using xslt. example code appreciated.

in example, don't seem have other namespaces 1 want remove. so, here example of xslt stylesheet, removes all namespaces elements (not ost:).

<xsl:stylesheet version="1.0"                 xmlns:xsl="http://www.w3.org/1999/xsl/transform">    <!-- identity template: copy is... -->   <xsl:template match="@*|node()">     <xsl:copy>       <xsl:apply-templates select="@*|node()"/>     </xsl:copy>   </xsl:template>    <!-- ... except elements,         create named element without namespace -->   <xsl:template match="*">     <xsl:element name="{local-name()}">       <xsl:apply-templates select="@*|node()"/>     </xsl:element>   </xsl:template>  </xsl:stylesheet> 

it uses identity transformation copy as-is, overrides elements create element same local name, no namespace.

if want remove ost: namespace, can include namespace declaration namespace, , change latter template match ost:*.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -