Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 27th, 2004, 04:09 AM
Authorized User
 
Join Date: Sep 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default funny results....

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


 
Old September 27th, 2004, 04:39 AM
Authorized User
 
Join Date: Jul 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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



 
Old September 27th, 2004, 04:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

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>
 
Old September 27th, 2004, 05:38 AM
Authorized User
 
Join Date: Sep 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help guys!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit Query Results in Results Grid druid2112 SQL Server 2005 1 June 28th, 2007 08:49 AM
Funny date return needelp Access VBA 3 September 19th, 2006 11:37 PM
Almost finished helpful code--funny ambrosia Word VBA 2 March 27th, 2006 09:21 PM
User-Level Security Wizard acting funny Bob Bedell Access 1 January 7th, 2006 02:53 AM
Isolation of results CFerthorney Beginning PHP 5 February 23rd, 2004 09:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.