[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] xslt 2. index-of, nodes


Subject: RE: [xsl] xslt 2. index-of, nodes
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 4 Jul 2003 11:27:42 +0100

No, I was wrong, it's not a Saxon bug.

You are doing

<xsl:for-each-group select="rec[mu/loc]">

but there is only one "rec" element in your data, so of course there is
only one group and only one item in that group.

I suspect you meant to do select="rec/mu[loc]", or something similar.

Michael Kay



> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> David.Pawson@xxxxxxxxxxx
> Sent: 04 July 2003 09:25
> To: jeni@xxxxxxxxxxxxxxxx
> Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] xslt 2. index-of, nodes
> 
> 
> > I don't think it should in your example, assuming that side 
> is always 
> > 'left' or 'right'. Can you put together a small example 
> showing it not 
> > working? (Of course it might be a Saxon bug.)
> 
> Below. small enough xml, full stylesheet.
> I couldn't shrink the stylesheet.
> Worked round the concat problem using string-join
> (what funny syntax!)
> 
> I expect this to produce 9 <circle> since each loc entry is 
> unique. It produces one, the first one in the file.
> 
> Is string join doing a 1.0 and only pulling the first node?
> 
> regards DaveP
> 
> xml.
> 
> <recs>
>  <intro>
>   <para>Position: wrt  enumeration; Suffixed with i= inner, 
> o=outer, t=t</para>
>   <para>intns: on scale low 0, high 0</para>
>  </intro>
> 
>  <!-- test -->
> 
> <rec>
>   <date>2003-06-23</date>
>   <mu>
>    <loc hl="upper" side="right" loc="3" />
>    <intns>1</intns>
>   </mu>
>   <mu>
>    <loc hl="upper" side="right" loc="4" />
>    <intns>1</intns>
>   </mu>
>   <mu>
>    <loc hl="upper" side="right" loc="5" />
>    <intns>1</intns>
>   </mu>
>  <mu>
>    <loc hl="upper" side="right" loc="6" />
>    <intns>1</intns>
>   </mu>
>  <mu>
>    <loc hl="upper" side="right" loc="7" />
>    <intns>1</intns>
>   </mu>
>  <mu>
>    <loc hl="upper" side="right" loc="8" />
>    <intns>1</intns>
>   </mu>
>  <mu>
>    <loc hl="lower" side="right" loc="8" />
>    <intns>1</intns>
>   </mu>
>  <mu>
>    <loc hl="lower" side="right" loc="7" />
>    <intns>1</intns>
>   </mu>
>  <mu>
>    <loc hl="lower" side="right" loc="6" />
>    <intns>1</intns>
>   </mu>
> 
> 
>  <!-- end test -->
> 
>  </rec>
> 
> </recs>
> 
> 
> 
> stylesheet:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:t="www.dpawson.co.uk#ns" xmlns:svg='http://www.w3.org/2000/svg' 
>   xmlns:fn="http://www.w3.org/2002/11/xquery-functions"
>   xmlns:xs="http://www.w3.org/2001/XMLSchema-datatypes"
>   xmlns:op="http://www.w3.org/2002/11/xquery-operators"
>                 version="2.0">
> 
>   <xsl:variable name="xExtent" select="1000"/>
> <xsl:variable name="yExtent" select="600"/>
>   <xsl:output method="xml"
> indent="yes"
> doctype-public="-//W3C//DTD SVG 1.0//EN" 
> doctype-system="http://www.w3.org/TR/2001/REC-SVG-20010904/DTD
> /svg10.dtd"
> />
> 
>   <xsl:template match="/">
>     <xsl:processing-instruction
> name="xml-stylesheet">
>  type='text/css' href='mu.css' 
>     </xsl:processing-instruction>
> <svg xmlns='http://www.w3.org/2000/svg' 
> xmlns:xlink='http://www.w3.org/1999/xlink'  
> width ='1000'
>  height='600'
> viewBox='0 0 1000 600 '  >
>         <xsl:apply-templates/>
>       </svg>
>   </xsl:template>
> 
>   <xsl:template match="recs">
>     <xsl:message>
>       <xsl:value-of select="count(rec/mu[loc])"/> records
>     </xsl:message>
>      <svg:rect x="1" y="1" width="{$xExtent -20}" 
> height="{$yExtent - 10}"
>         fill="none" stroke="blue" />
> 
>        <xsl:for-each-group select="rec[mu/loc]"         
>          
> group-by="string-join((mu/loc/@hl,mu/loc/@side,mu/loc/@loc), '+') ">
>              <xsl:for-each select="current-group()">
>                <xsl:variable name="context" select="mu[loc][1]/loc"/>
>                <xsl:variable name="loc" 
> select="number(mu[1]/loc/@loc)" />
>                <xsl:variable name="yoffs" 
> select="document('')//t:arc/y[$loc]"/>
>                <xsl:variable name="xpos">
>                  <xsl:if test="$context/@side='left'">
>                    <xsl:value-of select="(9 - $loc) * 
> ($xExtent div 16)"/>
>                  </xsl:if>
>                  <xsl:if test="$context/@side='right'">
>                    <xsl:value-of select="($loc * $xExtent div 
> 16) + 500"/>
>                  </xsl:if>
>                </xsl:variable>
>                
>                <xsl:variable name="ypos" >
>                  <xsl:if test="$context/@hl='upper'">
>                    <xsl:value-of select="xs:integer($yoffs)"/>
>                  </xsl:if>
>                  <xsl:if test="$context/@hl='lower'">
>                    <xsl:value-of select="xs:integer(600 - $yoffs)" />
>                  </xsl:if>
>                </xsl:variable>
>              
>                <xsl:variable name="order" select="position()"/>
> 
>                <xsl:message>
>              [<xsl:value-of select="$context/@hl"/> 
> <xsl:value-of select="$context/@side"/> <xsl:value-of 
> select="$context/@loc"/>]
>              </xsl:message>
>                  <xsl:if test="position()= last()">
>                    <svg:g>
>                    <svg:text x="{$xpos+10}" y="{$ypos + 
> ($order * 10) - 20}" class="fil3 fnt0 str0">
>                      <xsl:value-of select="date"/> -
>                      <xsl:value-of 
> select="count(current-group())"/> [<xsl:value-of 
> select="$context/@hl"/>&#xa0; <xsl:value-of 
> select="$context/@side"/>&#xa0; <xsl:value-of 
> select="$context/@loc"/>]
>                    </svg:text>
>                  
>                    <xsl:call-template name="loc">
>                    <xsl:with-param name="context" select="$context"/>
>                  </xsl:call-template>
>                </svg:g>
>                </xsl:if>
>             
>              </xsl:for-each>
>          
>      </xsl:for-each-group>
>   </xsl:template>
> 
> 
> 
> 
>   <xsl:template match="intro"/>
> 
>  
> 
> 
>   <xsl:template match="rec">
>     <xsl:if test="mu/loc">
>       <xsl:apply-templates select="mu" mode="draw"/>
>     </xsl:if>
>   </xsl:template>
> 
>  
> 
> 
> 
> 
> 
>   <xsl:template match="mu" mode="draw">
>     <xsl:apply-templates select="loc"/>
>   </xsl:template>
> 
> 
> 
>   <xsl:template name="loc">
>     <xsl:param name="context" />
>       <xsl:variable name="loc" select="number($context[1]/@loc)"/>
>     <xsl:variable name="yoffs" select="document('')//t:arc/y[$loc]"/>
>   
>       <xsl:variable name="xpos">
>         <xsl:if test="$context/@side='left'">
>           <xsl:value-of select="(9 - $loc) * ($xExtent div 16)"/>
>         </xsl:if>
>         <xsl:if test="$context/@side='right'">
>           <xsl:value-of select="($loc * $xExtent div 16) + 500"/>
>         </xsl:if>
>       </xsl:variable>
> 
>       <xsl:variable name="ypos">
>           <xsl:if test="$context/@hl='upper'">
>           <xsl:value-of select="$yoffs"/>
>         </xsl:if>
>         <xsl:if test="$context/@hl='lower'">
>           <xsl:value-of select="600 - $yoffs"/>
>         </xsl:if>
>       </xsl:variable>
>   <xsl:message>
>                  x  <xsl:value-of select="$xpos"/> 
>                  y  <xsl:value-of select="$ypos" separator=" ,"/> 
>                  loc <xsl:value-of select="$loc"/> 
>                  yoffset   <xsl:value-of select="$yoffs" 
> separator=" ,"/> 
>                </xsl:message>
>     
>         <svg:circle fill="red" r="10" stroke="blue" 
> stroke-width="1" cx="{$xpos}" cy="{$ypos}" /> 
>   </xsl:template>
> 
> 
> 
>   <xsl:template match="*">
>     <svg:g>
>       <svg:text x="100" y="100" class="fil3 fnt0 str0">
>         *****<xsl:value-of select="name(..)"/>/<xsl:value-of
> select="name()"/>******
>     </svg:text>
>   </svg:g>
>   <xsl:message terminate="yes">
>     Oops <xsl:value-of select="name(..)"/>/<xsl:value-of 
> select="name()"/> not styled
>   </xsl:message>
> </xsl:template>
> 
> 
> <t:arc>
>   <y>0</y>
>   <y>30</y>
>   <y>64</y>
>   <y>90</y>
>   <y>125</y>
>   <y>160</y>
>   <y>200</y>
>   <y>240</y>
> </t:arc>
> 
>  
> </xsl:stylesheet>
> 
> - 
> 
> NOTICE: The information contained in this email and any 
> attachments is 
> confidential and may be legally privileged. If you are not the 
> intended recipient you are hereby notified that you must not use, 
> disclose, distribute, copy, print or rely on this email's content. If 
> you are not the intended recipient, please notify the sender 
> immediately and then delete the email and any attachments from your 
> system.
> 
> RNIB has made strenuous efforts to ensure that emails and any 
> attachments generated by its staff are free from viruses. However, it 
> cannot accept any responsibility for any viruses which are 
> transmitted. We therefore recommend you scan all attachments.
> 
> Please note that the statements and views expressed in this email 
> and any attachments are those of the author and do not necessarily 
> represent those of RNIB.
> 
> RNIB Registered Charity Number: 226227
> 
> Website: http://www.rnib.org.uk 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords