Subject: funny results....
Posted By: richjo100 Post Date: 9/27/2004 4:09:11 AM
Hello all
Consider the following xml and xlst

xml:
=============================================================
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="err5.xsl"?>
<start>
 
  <build>
        <message>err1</message>
  </build>
  <build>
         <message222>err2</message222>
  </build>
  <random>
          <message>err3</message>
  </random>
  <build>
          <message>bla</message>
  </build>
  <build>
     <target>
       <build>
          <message>stuff blah5 stuffaft</message>
          <message>stuff  blah1 stuffaft</message>
          <message>stuff blah2 stuffaft</message>
          <message>stuff blah3 stuffaft</message>
          <message>stuff blah4 stuffaft</message>
          <message>stuff blah5 stuffaft</message>
          <message>stuff blah5 stuffaft</message>
          <message>stuff blah5 stuffaft</message>
          <message>stuff blah5stuffaft</message>
          <message>stuff blah12stuffaft </message>
          <message>stuff blah5 stuffaft</message>
          <message>stuff blah1 stuffaft</message>
          <message>stuff blah4 stuffaft</message>
       </build>
     </target>
  </build>
</start>

=============================================================

xlst:
=============================================================

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


  <xsl:template match="/">
      <xsl:apply-templates select="start/build/*" />
  </xsl:template>

  <xsl:template match="message[contains(., 'blah1')]">
     <xsl:for-each select="following-sibling::message[following-sibling::message[contains(., 'blah12')]]">
            <xsl:value-of select="." /><br />
     </xsl:for-each>
  </xsl:template>

  <xsl:template match="message" />

</xsl:stylesheet>

===========================================================

Now the results I get is

err2stuff blah2 stuffaft
stuff blah3 stuffaft
stuff blah4 stuffaft
stuff blah5 stuffaft
stuff blah5 stuffaft
stuff blah5 stuffaft
stuff blah5stuffaft


Why do I get err2 through at the beginning. Ithought I was only outputting stuff between blah1 and blah12 and with message tag. Err2 is not between blah1/blah12 and is also not in message tag but message222 tag.

What is going on?

Cheers
Richard


Reply By: barcher Reply Date: 9/27/2004 4:39:55 AM
Hi Richard,

You have used start/build/* which will match message222.
The default template will be used (as you have not specified one) for message222 will simply output its text value (ie. "err2").

To supress this you must define a custom template:
  
   <xsl:template match="message222" /> or do not use *

Regards
Bryan



Reply By: pgtips Reply Date: 9/27/2004 4:48:51 AM
To pick out all the messages between blah1 and blah12, can't you just use:

<xsl:template match="message[preceding-sibling::message[contains(., 'blah1')] and following-sibling::message[contains(., 'blah12')]]">
    <xsl:value-of select="."/>
    <br/>
</xsl:template>
Reply By: richjo100 Reply Date: 9/27/2004 5:38:06 AM
Thanks for your help guys!


Go to topic 17970

Return to index page 763
Return to index page 762
Return to index page 761
Return to index page 760
Return to index page 759
Return to index page 758
Return to index page 757
Return to index page 756
Return to index page 755
Return to index page 754