Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Question node array dynamic ????

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 5/14/2009 12:11:00 PM
Ssemi™ wrote:

> here xml data
> 
> <section title="country" view="1">
>    <submenu title="Bangkok">
>    <submenu title="Manila">
>    <submenu title="Cebu">
> </section


Consider to post well-formed XML, the above is far from being 
well-formed. Assuming the XML is as follows:

<section title="country" view="1">
    <submenu title="Bangkok"/>
    <submenu title="Manila"/>
    <submenu title="Cebu"/>
</section>


> xsl data
> 
> <xsl:template match="/">
> 	<xsl:apply-templates select="//section" />
> </xsl:template>
> 
> <xsl:template match="section">
>     <xsl:variable name="viewnum" select="@view" />
>      <xsl:value-of select="submenu[$viewnum]/@title" />
> </xsl:template>
> 
> result
>     Nothing.

then I can't reproduce the problem with the following stylesheet:

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

   <xsl:template match="/">
	<xsl:apply-templates select="//section" />
</xsl:template>

<xsl:template match="section">
     <xsl:variable name="viewnum" select="@view" />
      <xsl:value-of select="submenu[$viewnum]/@title" />
</xsl:template>

</xsl:stylesheet>

as it does not output nothing but rather 'Bangkog'.

However doing submenu[$viewnum]/@title is probably not what you want, 
you rather want
   submenu[position() = $viewnum]/@title
as that way you get what you want, namely you select the 'title' 
attribute value for that 'submenu' element which is at position $viewnum 
of all 'submenu' child elements.

Doing
   submenu[$viewnum]
where $viewnum is a string as in your case would convert that string to 
a boolean value and any non-empty string converts to true meaning
   submenu[$viewnum]
is
   submenu[true()]
which is the same as
   submenu
and finally
   <xsl:value-of select="submenu[$viewname]/@title
would always output the 'title' attribute of the first 'submenu' child.

-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent