RE: [xsl] how to applied "xpath-default-namespace" within call templates

Subject: RE: [xsl] how to applied "xpath-default-namespace" within call templates
From: "Joga Singh Rawat" <jrawat@xxxxxxxxxxxxxx>
Date: Sun, 17 Jun 2012 16:54:03 +0530
Thanks Michael!!! 

-----Original Message-----
From: Michael Kay [mailto:mike@xxxxxxxxxxxx] 
Sent: Sunday, June 17, 2012 4:23 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] how to applied "xpath-default-namespace" within call
templates

In your xsl:variable declaration, where it gives the required type 
as="element(attribute)", the unprefixed QName "attribute" is implicitly 
qualified by xpath-default-namespace, so it is expecting an element in 
the namespace http://www.elsevier.com/xml/bk/dtd. But when you create 
the element with the unprefixed name "attribute", the namespace is null, 
because it is taken from the relevant xmlns="..." declaration in the 
stylesheet, which does not exist. The simplest solution is to add 
xmlns="http://www.elsevier.com/xml/bk/dtd"; to the <attribute> element 
within the xsl:with-param.

Michael Kay
Saxonica

On 17/06/2012 10:29, Joga Singh Rawat wrote:
> Hi All,
> I am not able to get below "required output". I am getting below error by
> Oxygen. It is necessary to include
> "xpath-default-namespace="http://www.elsevier.com/xml/bk/dtd"; as one of
the
> attribute of<xsl:stylesheet>.
>
> Frror: E [Saxon-PE 9.3.0.5] Required item type of value of variable
> $attributes is {http://www.elsevier.com/xml/bk/dtd}attribute; supplied
value
> has item type element(attribute,
{http://www.w3.org/2001/XMLSchema}untyped)
>
>
> Input
> <chapter docsubtype="chp" id="chapter1" version="5.2" xml:lang="en"
>              xmlns="http://www.elsevier.com/xml/bk/dtd";
>              xmlns:ce="http://www.elsevier.com/xml/common/dtd";
>              xmlns:sb="http://www.elsevier.com/xml/common/struct-bib/dtd";>
>    <ce:table id="para1" frame="topbot" rowsep="0"
colsep="0">....</ce:table>
> </chapter>
>
> Stylesheet
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>    xmlns:xs="http://www.w3.org/2001/XMLSchema";
>    xmlns:xsd="http://www.w3.org/2001/XMLSchema";
>    xmlns:ce="http://www.elsevier.com/xml/common/dtd";
>    xmlns:sb="http://www.elsevier.com/xml/common/struct-bib/dtd";
>    xpath-default-namespace="http://www.elsevier.com/xml/bk/dtd"; 
>    exclude-result-prefixes="xs xsd ce sb " version="2.0">
>
>    <xsl:template match="ce:table">
>      <p>
>        <xsl:call-template name="collate-attributes">
>          <xsl:with-param name="attributes" as="element(attribute)+">
>            <attribute name="frame" display="para Frame" other-values="top,
> all, none, topbot, sides, bottom"/>
>          </xsl:with-param>
>        </xsl:call-template>
>        <xsl:apply-templates/>
>      </p>
>    </xsl:template>
>
>    <xsl:template name="collate-attributes">
>      <xsl:param name="attributes" required="yes"
as="element(attribute)*"/>
>      <xsl:variable name="here" select="."/>
>      <xsl:attribute name="showattrib">
>        <xsl:for-each select="$attributes">
>          <xsl:variable name="name" select="@name"/>
>          <xsl:variable name="display" select="@display"/>
>          <xsl:variable name="there" select="$here/@*[name() eq $name]"/>
>          <xsl:if test="not(position() eq 1)">|</xsl:if>
>          <xsl:value-of select="$name"/>
>          <xsl:text>@</xsl:text>
>          <xsl:value-of select="$display"/>
>          <xsl:text>:</xsl:text>
>          <xsl:value-of select="$there"/>
>          <xsl:for-each select="tokenize(@other-values,';')[not(. eq
> $there)]">
>            <xsl:value-of select="concat(';',.)"/>
>          </xsl:for-each>
>
>        </xsl:for-each>
>      </xsl:attribute>
>    </xsl:template>
> </xsl:stylesheet>
>
> Required Output:
> <p showattrib="frame@para Frame:topbot;top, all, none, topbot, sides,
> bottom">....</p>
>
> Thanks
> ...JSR

Current Thread