xsl-list
[Top] [All Lists]

Re: [xsl] double document merge using keys

2010-06-24 15:43:26
By default, if you compare two untyped attributes using gt with an XSLT 2.0 processor, it compares them as strings, not as numbers. You should either make your processing schema-aware so it knows these attributes are numbers, or you should force them to be numbers by explicit casting.

Michael Kay
Saxonica

On 24/06/2010 19:58, Terry Ofner wrote:
Okay, when I try this template, I get unusual return.


<xsl:variable name="stand2page" select="document('teks2page2.xml')"/>

<xsl:template match="chapter">
        <xsl:for-each select="Chapterlesson">
         <xsl:copy>
             <xsl:copy-of select="@*"/>
             <xsl:apply-templates/>
             <xsl:variable name="localStart" select="startNum"/>
             <xsl:variable name="localEnd" select="endNum"/>
             <xsl:for-each select="$stand2page">
                  <range><xsl:copy-of select="$stand2page/standards/stand[(_at_)startNum&gt;= 
$localStart and @startNum&lt;= $localEnd]"/></range>
              </xsl:for-each>
       </xsl:copy>
      </xsl:for-each>
</xsl:template>


Everything is good until we get to the triple digits:
<Chapterlesson code="6.1.2">
       <ch>1</ch>
       <lesson>Collaborating Through the Writing Process</lesson>
       <startNum>13</startNum>
       <endNum>32</endNum>
       <range>
          <stand startNum="13" endNum="14">14.A.2</stand>

          <!--I removed a bunch from here-->

          <stand startNum="30" endNum="30">14.D.3</stand>
          <stand startNum="31" endNum="31">14.E.3</stand>
          <stand startNum="132" endNum="132">16.A.2</stand>
          <stand startNum="133" endNum="133">14.A.1</stand>
                <!--many more like thes-->
</range>
</Chapterlesson>

Something is going wrong with the math. Is it seeing startNum="133" and seeing 
13 or something?


On Jun 24, 2010, at 10:46 AM, Martin Honnen wrote:

Terry Ofner wrote:

I have a set of standards that need to be aligned with each lesson. The 
standards are coded to the page, not the lesson. Here is a snippet of the 
current xml of standardDoc.xml:
<standards>
   <stand startNum="5" endNum="5">19.A.4</stand>
   <stand startNum="11" endNum="11">14.D.2</stand>
   <stand startNum="11" endNum="11">14.D.3</stand>
   <stand startNum="13" endNum="14">14.A.2</stand>
   <stand startNum="15" endNum="15">14.A.1</stand>
   <stand startNum="16" endNum="16">14.A.1</stand>
....
</standards>
The following stylesheet works as far as it goes. It only captures the standards that 
match the start page of the lesson. What I need is way to address standards with 
startNum>= $localStart and<= $localEnd. Is there a way to do this using keys?
<xsl:template match="Chapterlesson">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates/>
            <xsl:variable name="localStart" select="startNum"/>
            <xsl:variable name="localEnd" select="endNum"/>
            <xsl:for-each select="$stand2page">
                <stand><xsl:copy-of select="key('standPage', 
$localStart)"/></stand>
            </xsl:for-each>
I am not sure the a key helps with a less than/greater than condition but you 
could certainly use e.g.
              <xsl:copy-of select="$stand2page/standards/stand[(_at_)startNum>= $localStart 
and @endNum&lt;= $localEnd]"/>
to simply formulate the condition with XPath.



--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>