xsl-list
[Top] [All Lists]

RE: Filtering out books with short description

2005-07-20 06:33:10
Hello,

and thank you for the script. Is seems to work. I have one question
regarding this script. In the line:

<xsl:apply-templates select="book[string-length(description) &gt;
5]" /> 

Is it ensured that (description) only considers "description" being a direct
child of "book". What would happen if there would (sometimes) be another
"description" tag deeper inside the structure. Would this script than also
pick on that one? If yes, how could this be avoided. I checked in my output
(please remember, my orginal datastructure is much more complicated) and it
seems only to consider /book/description but I can't really explain why that
should be...

The second question is: What does "&gt" mean?

Karl



<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml" indent="yes" encoding="UTF-8" />
  <xsl:strip-space elements="*" />

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="bookshelf">
    <bookshelf>
      <xsl:apply-templates select="book[string-length(description) &gt;
5]" />
    </bookshelf>
  </xsl:template>

  <xsl:template match="book">
    <xsl:copy-of select="." />
  </xsl:template>

</xsl:stylesheet>
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Karl Koch <TheRanger(_at_)gmx(_dot_)net>
Sent:     Tue, 19 Jul 2005 20:38:19 +0200 (MEST)
To:       "Mulberry list" <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject:  [xsl] Filtering out books with short description

Hello experts,

all my postings here relate to a number of problems regarding one set of
content I have to solve. I have a list of books (simplified to make our
lifes easier:). This content needs to be transformed for various purposes.

<bookshelf>
  <book>
    <title>First book</title>
    <description>text text text</description>
  </book>
  <book>
    <title>Second book</title>
    <description>text text</description>
  </book>
  <book>
    <title>Third book</title>
    <description>text</description>
  </book>
</bookshelf>

I would like to filter out all books with short descriptions. How can I do
that? I curretnly see two different ideas of how this could be done (text
lengh and number of text tokens) and wonder if you can help me with one or
perhaps even both of them?

1) Copy only books with a description text of at least 5 letters in the
resulting XML file. That would remove the third book. The result would
only
contain the first and teh second book. How can I do that?

2) Copy only books with at least 3 text tokens in the description element.
After doing that only the first book would arrive in the resulting XML
file.
Is there a way to do that with XSLT? I am using XALAN.

Kind Regards and many thanks in advance,
Karl

-- 
GMX DSL = Maximale Leistung zum minimalen Preis!
2000 MB nur 2,99, Flatrate ab 4,99 Euro/Monat:
http://www.gmx.net/de/go/dsl

--~------------------------------------------------------------------
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>
--~--


-- 
5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail
+++ GMX - die erste Adresse f�r Mail, Message, More +++

--~------------------------------------------------------------------
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>