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 that accepts user search words and
displays documents that matches the search keywords. When a user
types in keywords to search in documents, I get XML from the back-
end server that looks like the above XML. The user entered search
words will be
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 as specified below:
desired output
..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 like
..test1 test2 test3 test4 test5 test6...
..test7...
But I want my output to look like the one specified under "desired
output"
current XSL
<xsl:template match="IMPORTANT">
<xsl:if test="$displaySnippets='true'">
<xsl:if test="position() < $numsnippets">
<br/>...<xsl:apply-templates/>...
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match="Hit | important">
<xsl:choose>
<xsl:when test="$displayImportants='true'">
<xsl:if test="position() < $important">
<xsl:apply-templates/>
</xsl:if>
</xsl:when>
<xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
</xsl:choose>
</xsl:template>
What should I change in my current XSL so that I get the desired output?
Thanks for the help.
-Mani
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list