Dieter Menne
Dieter Menne

Reputation: 10215

Lost in namespace: How to access default namespace item in XSLT

Given this xml

<?xml version="1.0" encoding="UTF-8"?>
<h:html xmlns="http://www.w3.org/2002/xforms" 
        xmlns:h="http://www.w3.org/1999/xhtml" 
        >
  <h:head>
    <h:title>h:Title</h:title>
    <title>Default Title</title>
  </h:head>
</h:html>


how do I access Default Title in XSLT? I can easily get h:title

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
   xmlns="http://www.w3.org/2002/xforms"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
   xmlns:h="http://www.w3.org/1999/xhtml" 
   >
 <xsl:template match="h:html/h:head">
   <xsl:value-of select="h:title"/>
   <xsl:value-of select="title"/>
 </xsl:template>

</xsl:stylesheet>


Upvotes: 0

Views: 44

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117102

how do I access Default Title

Like this?

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:h="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xf h">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="h:html/h:head">
    <root>
        <title-h>
            <xsl:value-of select="h:title"/>
        </title-h>
        <title-xf>
            <xsl:value-of select="xf:title"/>
        </title-xf>
    </root>
</xsl:template>

</xsl:stylesheet>

For explanation, see: https://stackoverflow.com/a/34762628/3016153

Upvotes: 1

Related Questions