[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSL Word counting and Merging

Subject: XSL Word counting and Merging
From: Mani Malarvannan <mani@xxxxxxxxxxxx>
Date: Mon, 23 Dec 2002 09:52:14 -0600
test1 test2 test3 test4
Hello,
I've a following XML. 

<?xml version="1.0" encoding="iso-8859-1"?>
<search-result>
<document-list>
<document>
<important>
<p>
<IMPORTANT>test1 test2 test3 test4 test5 test6</IMPORTANT>
</p>
<b>
<IMPORTANT>test7</IMPORTANT>
</b>
<p>
<b>
<IMPORTANT>test8</IMPORTANT>
</b>
<IMPORTANT> test9 test10 <Hit n-wordpos="6879">Auto</Hit> test1 test2 
test3 test4 test5 test6 test7 test8 test9 test10 </IMPORTANT>
</p>
</important>
</document>
<document>
<important>
<p>
<IMPORTANT>test1 test2 </IMPORTANT>
<iref dest="59">
<IMPORTANT>test3</IMPORTANT>
</iref>
<IMPORTANT>) test4 test5 test6 test7 test8 test9 test10 <Hit n-wordpos="15570">Auto</Hit> 
test1 test2 test3 test4 test5 test6 test7 test8 test9 test10</IMPORTANT>
</p>
</important>
</document>
<document>
<important>
<p>
<IMPORTANT>test1 test2 test3 test4 test5 test6 test7 test8 test9 
test10 <Hit n-wordpos="19548">Auto</Hit>test1 test2 test3 test4 test5 
test6 test7 test8 test9 test10</IMPORTANT>
</p>
<p>
<IMPORTANT>test1 test2 test3 test4 test5 test6 test7 test8</IMPORTANT>
<scaps>
<IMPORTANT>test9</IMPORTANT>
</scaps>
<IMPORTANT>test10<Hit n-wordpos="35689">Auto</Hit> test1 test2 test3 
</IMPORTANT>
<scaps>
<IMPORTANT>test4</IMPORTANT>
</scaps>
<IMPORTANT>test5 test6 test7 <Hit n-wordpos="35696">Auto</Hit> test1 
test2 test3 test4 test5 test6 test7 test8 test9 test10 </IMPORTANT>
</p>
<p>
<IMPORTANT>test1 test2 test3 test4 test5 test6 test7 test8 test9 
test10  <Hit n-wordpos="39554">Auto</Hit> itest1 test2 test3 test4 
test5 test6 test7 test8 test9 test10 </IMPORTANT>
</p>
<p>
<IMPORTANT>test1 test2 test3 test4 test5 test6 test7 test8 test9 
test10  <Hit n-wordpos="46008">Auto</Hit> test1 test2 test3 test4 
test5 test6 test7 test8 test9 test10 </IMPORTANT>
</p>
<p>
<IMPORTANT>test1 test2 test3 test4 test5 test6 test7 test8 </IMPORTANT>
<b>
<IMPORTANT>test9 test10  <Hit n-wordpos="52292">Auto</Hit>
</IMPORTANT>
</b>
<IMPORTANT> test1 test2 test3 test4 test5 test6 test7 test8 test9 
test10</IMPORTANT>
</p>
<p>
<IMPORTANT>test1 test2 test3 test4 test5 test6 test7 test8 test9 
test10<Hit n-wordpos="65109">Auto</Hit> test1 test2 test3 test4 test5 
test6 test7 test8 test9 test10</IMPORTANT>
</p>
<b>
<IMPORTANT>test1</IMPORTANT>
</b>
<b>
<IMPORTANT>test2 test3</IMPORTANT>
</b>
<p>
<IMPORTANT>test4 test5 test6 test7 test8 test9 test10 <Hit n-wordpos="77364">Auto</Hit> 
test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 </IMPORTANT>
</p>
</important>
</document>
</document-list>
</search-result>







I'm working in an application, when a user types in keywords will 
display 10 words that appears before the keyword and 10 words that
appears after the keyword from a document. In a document there might 
be one or more hit words and the hit word is presented
in <Hit> tag. The words that comes before and after the <Hit> word 
is presented in <IMPORTANT>. Some times all the words
that comes before and after the keyword is presented in one <IMPORTANT> 
and some times it comes in several different <IMPORTANT> 
I want to combine the values of <IMPORTANT> that appears before and 
after <Hit> so that my output looks like

..test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 Auto 
test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 ...
..test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 Auto 
test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 ...


Currently I've following XSL that produces the output but it is not 
combining the values of <IMPORTANT>, instead it
outputs the values in a separate line.

<xsl:template match="IMPORTANT">
  <xsl:if test="$displaySnippets='true'">
   <xsl:if test="position() &lt; $numsnippets">
   <br/>...<xsl:apply-templates/>...
   </xsl:if>
  </xsl:if>
</xsl:template>

<xsl:template match="Hit | important">
  <xsl:choose>
    <xsl:when test="$displaySnippets='true'">
      <xsl:if test="position() &lt; $numsnippets">
        <xsl:apply-templates/>
      </xsl:if>
    </xsl:when>
    <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
  </xsl:choose>
</xsl:template>



I don't have any control on the XML format, so my choice is to modify 
the XSL so that I'll get the desired output.

Thanks for the help.

-Mani








 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.