RE: [xsl] getting stuck in context when using substring-before as test

Subject: RE: [xsl] getting stuck in context when using substring-before as test
From: "Miller, Mark" <Mark.Miller@xxxxxxxxxxxxxxxx>
Date: Tue, 24 Nov 2009 13:54:24 -0500
Thanks Michael, that works great.  I just needed a fresh pair of eyes to
see the obvious.

Mark Miller

-----Original Message-----
From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
Sent: Tuesday, November 24, 2009 1:49 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] getting stuck in context when using substring-before
as test


I suspect you should simply substitute "starts-with" for
"substring-before".
If X starts with Y, then substring-before(X,Y) is a zero-length string,
which equates to false, which seems to be exactly the opposite of what
you
intended.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay

> -----Original Message-----
> From: Miller, Mark [mailto:Mark.Miller@xxxxxxxxxxxxxxxx]
> Sent: 24 November 2009 18:41
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] getting stuck in context when using
> substring-before as test
>
> I have the following simplified xml file that I am
> transforming into an HTML table.  In the table I have a cell
> where I am placing three date values in an embedded table.  I
> am having trouble using the substring-before as a test to
> find the specific element that matches and then getting that
> elements data.  This case is very simple, there will be many
> Objects with 0 to 5 bObjRef elements, each of which will have
> its own cell with 3 date values displayed.
>
> Any guidance is greatly appreciated,
>
>
> Start Simple.xml...........................
> <ematrix>
>     <creationProperties>
>        <datetime>2009-11-24T07:12:50Z</datetime>
>     </creationProperties>
>     <Object>
>         <oname>Name001 (some text here)</oname>
>         <desc>description</desc>
>         <aList>
>             <attr>
>                 <name>Due Customer</name>
>                 <datetime>2009-08-10T00:00:00Z</datetime>
>             </attr>
>             <attr>
>                 <name>Submitted Date</name>
>                 <datetime>2009-08-10T00:00:00Z</datetime>
>             </attr>
>             <attr>
>                 <name>POC</name>
>                 <string>lastname</string>
>             </attr>
>             <attr>
>                 <name>Submittal Revision</name>
>                 <string>-</string>
>             </attr>
>             <attr>
>                 <name>Comments</name>
>                 <string>comments</string>
>             </attr>
>         </aList>
>         <fRelList>
>             <rel>
>                 <rRefDef>Subordinate Submittal</rRefDef>
>                 <rObj>
>                     <bObjRef>
>                         <oType>Submittal</oType>
>                         <oName>BMC4I-DD-04-06k-2010-08</oName>
>                     </bObjRef>
>                 </rObj>
>                 <attrList>
>                     <attr>
>                         <name>Due Customer</name>
>                         <datetime>2010-08-08T00:00:00Z</datetime>
>                     </attr>
>                     <attr>
>                         <name>Promised</name>
>                         <datetime>2010-08-08T00:00:00Z</datetime>
>                     </attr>
>                     <attr>
>                         <name>Submitted</name>
>                         <datetime>2010-08-07T00:00:00Z</datetime>
>                     </attr>
>                 </attrList>
>             </rel>
>             <rel>
>                 <rRefDef>Subordinate Submittal</rRefDef>
>                 <rObj>
>                     <bObjRef>
>                         <oType>Submittal</oType>
>                         <oName>CMR-DD-04-06k-2010-08</oName>
>                     </bObjRef>
>                 </rObj>
>                 <attrList>
>                     <attr>
>                         <name>Due Customer</name>
>                         <datetime>2009-08-10T00:00:00Z</datetime>
>                     </attr>
>                     <attr>
>                         <name>Promised</name>
>                         <datetime/>
>                     </attr>
>                     <attr>
>                         <name>Submitted</name>
>                         <datetime>2009-08-11T00:00:00Z</datetime>
>                     </attr>
>                 </attrList>
>             </rel>
>             <rel>
>                 <rRefDef>Subordinate Submittal</rRefDef>
>                 <rObj>
>                     <bObjRef>
>                         <oType>Submittal</oType>
>                         <oName>DD-LR-IPT-GE-04-06k-2010-08</oName>
>                     </bObjRef>
>                 </rObj>
>                 <attrList>
>                     <attr>
>                         <name>Due Customer</name>
>                         <datetime>2010-08-09T00:00:00Z</datetime>
>                     </attr>
>                     <attr>
>                         <name>Promised</name>
>                         <datetime/>
>                     </attr>
>                     <attr>
>                         <name>Submitted</name>
>                         <datetime>2010-08-12T00:00:00Z</datetime>
>                     </attr>
>                 </attrList>
>             </rel>
>         </fRelList>
>     </Object>
> </ematrix>
> End simple.xml...............................
>
> Start simple.xsl...............................
> <?xml version=3D"1.0" encoding=3D"iso-8859-1"?> <!DOCTYPE
> xsl:stylesheet [
> <!ENTITY nbsp   "&#160;">
> ]>
> <xsl:stylesheet version=3D"1.0"
> xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform";>
>   <xsl:output method=3D"html" encoding=3D"iso-8859-1"/>
>   <xsl:template match=3D"/">
>    =20
>     <html>
>       <head> </head>
>     <body> =20
>       <table border=3D"1">
>         <tr>
>           <th><div align=3D'center'>BMC4I</div></th>
>         </tr>
>         <tr>
>         <xsl:for-each select=3D"ematrix/Object">
>           <xsl:if
> test=3D"substring-before(fRelList/rel/rObj/bObjRef/oName,'BMC4I-')">
>             <td>
>               <table border=3D"0">
>                 <tr>
>                   <td><xsl:value-of
> select=3D"substring(aList/attr[name=3D'Due
> Customer']/datetime,1,10)"/>&nbsp;</td>
>                 </tr>
>                 <tr>
>                   <td><xsl:value-of
> select=3D"substring(aList/attr[name=3D'Promised']/datetime,1,1
> 0)"/>&nbsp
> ;=
> </t
> d>
>                 </tr>
>                 <tr>
>                   <td><xsl:value-of
> select=3D"substring(aList/attr[name=3D'Submitted']/datetime,1,
> 10)"/>&nbs
> p=
> ;</
> td>
>                 </tr>
>               </table>
>             </td>
>             </xsl:if>
>           </xsl:for-each>
>         </tr>
>       </table>
>       </body>
>       </html>   =20
>   </xsl:template>
> </xsl:stylesheet>
> End simple.xsl............................
> Start simple.htm..........................
> <html>
>    <head>
>    <table border=3D"1">
>       <tr >
>          <th>
>             <div align=3D"center">BMC4I</div>
>          </th>
>       </tr>
>       <tr>
>          <td>
>             <table border=3D"0" >
>                <tr>
>                   <td>2010-08-08</td>
>                </tr>
>                <tr>
>                   <td>2010-08-08</td>
>                </tr>
>                <tr>
>                   <td>2010-08-07</td>
>                </tr>
>             </table>
>          </td>
>       </tr>
>    </table>
> <body>
> End simple.htm....................................
>
>
> Mark J. Miller

Current Thread