How do I index XML data within a content node? - ibm-watson

I'm converting an XML document and want to dump the entire contents in a content node in the converter.
<xsl:template match="/">
<vce>
<document>
<content name="xml">
<xsl:copy-of select="." />
</content>
</document>
</vce>
</xsl:template>
This gives me a node with the name "XML" and my entire xml content within. However, this is removed when the normalization converter is run. Is there something special I need to do to index XML inside a content?

I was able to reference the converter: 'vse-converter-xml-to-vxml' to create a template that indexes the xml:
<xsl:template match="/">
<vce>
<document>
<content name="xml">
<xsl:apply-templates select="*" mode="xml-to-plain-text" />
</content>
</document>
</vce>
</xsl:template>
<xsl:template match="*" mode="xml-to-plain-text">
<xsl:text><![CDATA[<]]></xsl:text>
<xsl:value-of select="name()" />
<xsl:text> </xsl:text>
<xsl:choose>
<xsl:when test="text()|*|comment()">
<xsl:text>></xsl:text>
<xsl:apply-templates select="text()|*|comment()" mode="xml-to-plain-text" />
<xsl:text><![CDATA[</]]></xsl:text>
<xsl:value-of select="name()" />
<xsl:text>></xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>/></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Related

Repeat position within a loop in xslt

I have two nested loops. The first loop is picking up distinct value and comparing in second loop. In second loop i am giving position() and it is coming sequential as 1,2,3 but i want it to appear as 1,1,1 during first iteration and 2,2,2 in second iteration and 3,3,3 in third iteration and so on.
XML:
<root>
<Items>
<Item>
<ItemCode>12345</ItemCode>
<ItemColor>Red</ItemColor>
<Weight>1Kg</Weight>
</Item>
<Item>
<ItemCode>19087</ItemCode>
<ItemColor>Blue</ItemColor>
<Weight>1Kg</Weight>
</Item>
</Items>
<Items>
<Item>
<ItemCode>12345</ItemCode>
<ItemColor>Yellow</ItemColor>
<Weight>1Kg</Weight>
</Item>
<Item>
<ItemCode>19087</ItemCode>
<ItemColor>Green</ItemColor>
<Weight>1Kg</Weight>
</Item>
</Items>
</root>
Required Output:
12345
1.Red
1.Yellow
19087
2.Blue
2.Green
(Or)
1.12345
Red
Yellow
2.19087
Blue
Green
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="check" match="Items" use="ItemCode" />
<xsl:template match="root/Items">
<xsl:for-each select="Item[count(. | key('check', ItemCode)[1]) = 1]">
<xsl:value-of select="ItemCode"/>
<xsl:for-each select="key('check', ItemCode)">
<xsl:value-of select="position()"/>
<xsl:value-of select="ItemColor"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I am using xslt-1.0
Your help is appreciated. Thank you!
The following stylesheet:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8"/>
<xsl:key name="item-by-code" match="Item" use="ItemCode"/>
<xsl:template match="/root">
<xsl:for-each select="Items/Item[count(. | key('item-by-code', ItemCode)[1]) = 1]">
<xsl:value-of select="position()"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="ItemCode"/>
<xsl:for-each select="key('item-by-code', ItemCode)">
<xsl:text>
</xsl:text>
<xsl:value-of select="ItemColor"/>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
when applied yo your input example, will return:
Result
1.12345
Red
Yellow
2.19087
Blue
Green
Alternatively, you could do:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8"/>
<xsl:key name="item-by-code" match="Item" use="ItemCode"/>
<xsl:template match="/root">
<xsl:for-each select="Items/Item[count(. | key('item-by-code', ItemCode)[1]) = 1]">
<xsl:variable name="i" select="position()" />
<xsl:value-of select="ItemCode"/>
<xsl:text>
</xsl:text>
<xsl:for-each select="key('item-by-code', ItemCode)">
<xsl:value-of select="$i"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="ItemColor"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
to get:
12345
1.Red
1.Yellow
19087
2.Blue
2.Green

Calculating the sum of values from sibling elements using XSLT

I am working on an automatic transform of measurements using XSLT. The transform of single measurements from one system (e.q. imperial) to another (e.g. metric) is working fine. But imperial measurements may take the form '5 ft 10 in' and I would want to convert this into a single metric value.
In my XML model for I accommodate such combined measurements by allowing either a single value or multiple child nodes. So when I find that my has child nodes, I need to convert each one of those child elements to metric units and then add up the values to get one single metric result.
I am struggling to find the best way to process multiple child nodes and add up the resulting values. In an iterative language I would just process from the first to the next and update a global variable, but in XSLT I don't know if there is such a thing as a global variable that can be updated from subsequent calls to the same template.
Here is a (simplified) transform - this one handles only [ft_i] and [in_i] to m.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*,node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="measurement">
<xsl:copy>
<xsl:choose>
<xsl:when test="measurement">
<xsl:apply-templates select="*"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="normalise">
<xsl:with-param name="val" as="xs:double" select="number(text())"/>
<xsl:with-param name="unitin" select="#ucum"/>
<xsl:with-param name="count" as="xs:integer" select="1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template name="normalise">
<xsl:param name="val" as="xs:double"/>
<xsl:param name="unitin"/>
<xsl:param name="count" as="xs:integer"/>
<xsl:choose>
<xsl:when test="$unitin eq '[ft_i]'">
<xsl:attribute name="ucum">
<xsl:value-of select="'m'"/>
</xsl:attribute>
<xsl:attribute name="unit">
<xsl:value-of select="'m'"/>
</xsl:attribute>
<xsl:value-of select="$val * 0.3048"/>
</xsl:when>
<xsl:when test="$unitin eq '[in_i]'">
<xsl:attribute name="ucum">
<xsl:value-of select="'m'"/>
</xsl:attribute>
<xsl:attribute name="unit">
<xsl:value-of select="'m'"/>
</xsl:attribute>
<xsl:value-of select="$val * 0.0254"/>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
A simple test file:
<topic>
<p>This piece is
<measurement>
<measurement unit="ft"
ucum=" [ft_i]">10</measurement>
<measurement unit="in"
ucum="[in_i]">2</measurement>
</measurement>
long
</p>
</topic>
The transform gives this:
<topic>
<p>This piece is
<measurement>
<measurement ucum="m"
unit="m">3.048</measurement>
<measurement ucum="m"
unit="m">0.0508</measurement>
</measurement>
long
</p>
</topic>
Obviously, I would want to see this:
<topic>
<p>This piece is
<measurement ucum="m"
unit="m">3.0988</measurement>
long
</p>
</topic>
I could use an xsl:for-each on the child measurement nodes but how do I add the separate values to a global value which can then be output from the main template ?
Assuming that some values and attributes are constant the most simple approach would be using a complex XPath-2.0 expression. Then you can reduce your measurement template to:
<xsl:template match="measurement">
<measurement ucum="m" unit="m">
<xsl:copy-of select="sum(for $x in measurement return if (normalize-space($x/#ucum)= '[ft_i]') then xs:double(normalize-space($x))*0.3048 else xs:double(normalize-space($x))*0.0254)" />
</measurement>
</xsl:template>
It assumes that the attributes stay the same and that there are only two units. But you could easily extend it.
Building templates based on your approach, the following solution is also possible:
<xsl:template match="measurement">
<xsl:copy>
<xsl:variable name="summary">
<xsl:for-each select="measurement">
<val>
<xsl:call-template name="normalise">
<xsl:with-param name="val" as="xs:double" select="number(.)"/>
<xsl:with-param name="unitin" select="#ucum"/>
<xsl:with-param name="count" as="xs:integer" select="1"/>
</xsl:call-template>
</val>
</xsl:for-each>
</xsl:variable>
<xsl:copy-of select="$summary/val[1]/#*" />
<xsl:copy-of select="sum($summary/val)" />
</xsl:copy>
</xsl:template>
<xsl:template name="normalise">
<xsl:param name="val" as="xs:double"/>
<xsl:param name="unitin"/>
<xsl:param name="count" as="xs:integer"/>
<xsl:choose>
<xsl:when test="normalize-space($unitin) = '[ft_i]'">
<xsl:attribute name="ucum">
<xsl:value-of select="'m'"/>
</xsl:attribute>
<xsl:attribute name="unit">
<xsl:value-of select="'m'"/>
</xsl:attribute>
<xsl:value-of select="$val * 0.3048"/>
</xsl:when>
<xsl:when test="normalize-space($unitin) = '[in_i]'">
<xsl:attribute name="ucum">
<xsl:value-of select="'m'"/>
</xsl:attribute>
<xsl:attribute name="unit">
<xsl:value-of select="'m'"/>
</xsl:attribute>
<xsl:value-of select="$val * 0.0254"/>
</xsl:when>
</xsl:choose>
</xsl:template>
It is more flexible and uses a two-stage approach with the variable.
The result is the same. I guess if you combine both, you'll find a good way fitting your needs.
Assuming you can have more than just 2 units, it would be convenient to store them in a variable and retrieve the corresponding conversion factor using a key:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="unit" match="unit" use="#name" />
<xsl:variable name="units">
<unit name="ft" factor=".3048"/>
<unit name="in" factor=".0254"/>
<!-- add more units here ... -->
</xsl:variable>
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="measurement[measurement]">
<measurement ucum="m" unit="m">
<xsl:value-of select="sum(measurement/(. * key('unit', #unit, $units)/#factor))"/>
</measurement>
</xsl:template>
</xsl:stylesheet>
Demo: https://xsltfiddle.liberty-development.net/6rewNxT
No need for multi-pass processing -- XPath 2.0 is strong enough for this kind of problem:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="measurement[*]">
<measurement ucum="m" unit="m">
<xsl:value-of select=
"sum(measurement/(. * (if(#ucum eq '[ft_i]') then 0.3048 else 0.0254)))"/>
</measurement>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the provided XML document:
<topic>
<p>This piece is
<measurement>
<measurement unit="ft"
ucum="[ft_i]">10</measurement>
<measurement unit="in"
ucum="[in_i]">2</measurement>
</measurement>
long
</p>
</topic>
The wanted, correct result is produced:
<topic>
<p>This piece is
<measurement ucum="m" unit="m">3.0988</measurement>
long
</p>
</topic>
II. More Generic Solution
One can produce a more generic solution, where the conversion is isolated into a separate XSLT <xsl:function>. Do note that this solution will work even in cases when the conversion logic is so complex that it cannot be expressed in a single XPath expression as was possible in the solution above. If the conversion is not just a simple multiplication, then it is not possible in general to present it as a table and use xsl:key:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:f="my:f" exclude-result-prefixes="f">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="measurement[*]">
<measurement ucum="m" unit="m">
<xsl:value-of select="sum(measurement/f:convert(#ucum, .))"/>
</measurement>
</xsl:template>
<xsl:function name="f:convert">
<xsl:param name="pFromUnit"/>
<xsl:param name="pValue"/>
<xsl:value-of select=
"$pValue * (if($pFromUnit eq '[ft_i]') then 0.3048 else 0.0254)"/>
</xsl:function>
</xsl:stylesheet>
When this transformation is applied on the same XML document (above), the same correct, wanted result is produced again:
<topic>
<p>This piece is
<measurement ucum="m" unit="m">3.0988</measurement>
long
</p>
</topic>

Convert an xml array to another type of xml array using xslt

I've two xml files. Both are arrays of
person (having a lot of nodes underneath)
I need to convert this one
<result>
<sfobject>
<id></id>
<type>CompoundEmployee</type>
<person>
<lot of nodes/>
</person>
</sfobject>
<sfobject>
<id></id>
<type>CompoundEmployee</type>
<person>
<lot of nodes/>
</person>
</sfobject>
</result>
to
<queryCompoundEmployeeResponse>
<CompoundEmployee>
<id></id>
<person>
<lot of nodes/>
</person>
</CompoundEmployee>
<CompoundEmployee>
<id></id>
<person>
<lot of nodes/>
</person>
</CompoundEmployee>
</queryCompoundEmployeeResponse>
using xslt. I've this xslt for it.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="node()|#*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|#*" />
</xsl:copy>
</xsl:template>
<xsl:template match="sfobject/*[1]">
<queryCompoundEmployeeResponse>
<CompoundEmployee>
<id>
<xsl:value-of select="#id" />
</id>
<xsl:copy-of select="/*/person[1]" />
<xsl:call-template name="identity" />
</id>
</CompoundEmployee>
</queryCompoundEmployeeResponse>
</xsl:template>
<xsl:template match="/*/sfobject[1]" />
<xsl:param name="removeElementsNamed" select="'type'"/>
</xsl:stylesheet>
This doesn't check out well. I've done this before in groovy, but now this has to be converted to xslt as the system changed. I'm new to xslt and I'm sure I am to use an advanced level of xslt here. Any pointers are highly appreciated.
Is xslt the right tool at all here? Or should I stick to groovy?
You have three rules you need to implement, it seems
Rename result to queryCompoundEmployeeResponse
Rename sfobject to whatever is held in type
Remove type from under sfobject
Happuly, each rule here can actually be implemented as a separate template.
So, for rule 1, you do this...
<xsl:template match="result">
<queryCompoundEmployeeResponse>
<xsl:apply-templates />
</queryCompoundEmployeeResponse>
</xsl:template>
For rule 2, do this...
<xsl:template match="sfobject">
<xsl:element name="{type}">
<xsl:apply-templates select="node()|#*" />
</xsl:element>
</xsl:template>
And for rule 3, do this...
<xsl:template match="sfobject/type" />
You then use the identity template to handle all other nodes and attributes.
Try this XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="node()|#*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|#*" />
</xsl:copy>
</xsl:template>
<xsl:template match="result">
<queryCompoundEmployeeResponse>
<xsl:apply-templates />
</queryCompoundEmployeeResponse>
</xsl:template>
<xsl:template match="sfobject">
<xsl:element name="{type}">
<xsl:apply-templates select="node()|#*" />
</xsl:element>
</xsl:template>
<xsl:template match="sfobject/type" />
</xsl:stylesheet>

XSLT sort array values

I'm new on XSLT. I want to sort the following xml segment by XSLT. Does anyone know how to sort the inner array values?
<Coordinates>
<Array n="155" type="real">1909.090909090909 1894.7368421052631 1777.7777777777778 1923.076923076923 2000.0 3191.528925619835 3771.025641025641 4609.022727272727 6931.111111111111 7394.8611111111095 3149.4444444444443 4173.596491228071 6090.740740740741 7578.214285714285 7261.25 3369.7478260869566 5986.1621621621625 6515.15625 7138.875000000002 8225.714285714286 3224.5867768595035 6915.27027027027 8103.548387096775 6897.741935483871 8485.166666666666 3662.2988505747126 7968.2307692307695 7770.882352941177 6628.548387096775 8864.642857142857 3429.8863636363635 5785.285714285715 6576.428571428572 6791.8 8715.625 4015.2450980392155 7127.045454545455 6171.041666666667 9326.95652173913 10307.827586206897 3577.6136363636365 6820.000000000001 6308.913043478261 8907.0 9448.392857142857 3452.926829268293 7172.5 7280.0 8653.125 9277.692307692309 3108.3333333333335 4601.282051282052 6530.538461538462 8847.368421052632 8147.105263157895 3258.360655737705 7630.833333333335 6814.333333333333 5513.35294117647 9727.894736842105 2781.2500000000005 6974.21875 7172.5 6459.318181818182 8599.722222222223 3512.0454545454545 5203.5 7422.5 9705.454545454546 9217.631578947368 3608.7820512820513 6385.952380952381 9302.35294117647 6647.857142857143 8054.285714285715 ...
</Array>
</Coordinates>
I want to sort the real values by ascending order.
Thanks in advance.
If you are using the Xalan-J processor, you can take advantage of the EXSLT str:tokenize() extension function and do simply:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
extension-element-prefixes="str">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Array">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:for-each select="str:tokenize(., ' ')">
<xsl:sort select="." data-type="number" order="ascending"/>
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Otherwise you will have to tokenize the values using a recursive named template, then convert the result to a node-set before you can sort it:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Array">
<xsl:variable name="values">
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:variable>
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:for-each select="exsl:node-set($values)/value">
<xsl:sort select="." data-type="number" order="ascending"/>
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template name="tokenize">
<xsl:param name="text"/>
<xsl:param name="delimiter" select="' '"/>
<xsl:variable name="token" select="substring-before(concat($text, $delimiter), $delimiter)" />
<xsl:if test="$token">
<value>
<xsl:value-of select="$token"/>
</value>
</xsl:if>
<xsl:if test="contains($text, $delimiter)">
<!-- recursive call -->
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
One solution is to form a variable where each tag contains value. And then you can sort it by method , which works for number in xslt 1.0 too. As i can see, your values here are separated by a space.
ok, here is my solution. credit for a part goes to Does XSLT have a Split() function?
<xsl:template match="/">
<xsl:variable name="raw-data">
<xsl:value-of select="Coordinates/Array"/>
</xsl:variable>
<xsl:variable name="ids">
<xsl:if test="$raw-data">
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$raw-data" />
</xsl:call-template>
</xsl:if>
</xsl:variable>
<xsl:for-each select="msxsl:node-set($ids)/id">
<xsl:sort data-type="number" order="descending" select="."/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:template>
<xsl:template name="output-tokens">
<xsl:param name="list" />
<xsl:variable name="newlist" select="concat(normalize-space($list), ' ')" />
<xsl:variable name="first" select="substring-before($newlist, ' ')" />
<xsl:variable name="remaining" select="substring-after($newlist, ' ')" />
<id>
<xsl:value-of select="$first" />
</id>
<xsl:if test="$remaining">
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$remaining" />
</xsl:call-template>
</xsl:if>
</xsl:template>
p.s. edited - now with sort

Compare XSL values in array

I'm not sure how to title this post..
I want to compare pubDate between rows
Desired Output: Only print the pubDate when it is different from the previous row's pubDate. (my substring function returns Dec 2014, Jan 2015, etc)
Currently I have it set to print the pubDate every time. I just can't figure out how to compare the value between rows... please help!
Code excerpt:
<xsl:template match="item">
<xsl:variable name="Rows" select="channel/item"/>
<xsl:variable name="RowCount" select="count($Rows)"/>
<xsl:variable name="item_link" select="link"/>
<xsl:variable name="item_title" select="description"/>
<xsl:value-of select="$Rows"/>
<xsl:variable name="CurPosition" select="position()" />
<xsl:variable name="PrevPosition" select="position()-1" />
<xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
<xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
<xsl:if test="not(substring(pubDate,3,9) = 0)">
<div align="center">
<hr/>
<xsl:value-of select="substring(pubDate,3,9)" disable-output-escaping="yes"/>
</div>
</xsl:if>
<li>
<a href="{$item_link}" title="{$item_title}">
<xsl:variable name="SafeHtml">
<xsl:call-template name="GetSafeHtml">
<xsl:with-param name="Html" select="title"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$SafeHtml" disable-output-escaping="yes"/>
</a>
</li>
Here is the full code for anybody who wants it:
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
version="1.0" exclude-result-prefixes="xsl ddwrt msxsl rssaggwrt"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:rssaggwrt="http://schemas.microsoft.com/WebParts/v3/rssagg/runtime"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:rssFeed="urn:schemas-microsoft-com:sharepoint:RSSAggregatorWebPart">
<xsl:param name="rss_FeedLimit">30</xsl:param>
<xsl:param name="rss_ExpandFeed">true</xsl:param>
<xsl:param name="rss_LCID">1033</xsl:param>
<xsl:param name="rss_WebPartID">RSS_Viewer_WebPart</xsl:param>
<xsl:param name="rss_alignValue">left</xsl:param>
<xsl:param name="rss_IsDesignMode">True</xsl:param>
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="Rows" select="channel/item"/>
<xsl:variable name="RowCount" select="count($Rows)"/>
<div>
<xsl:apply-templates select="rss/channel"/>
</div>
</xsl:template>
<xsl:template match="rss/channel">
<xsl:variable name="link" select="link"/>
<xsl:variable name="description" select="description"/>
<ul>
<xsl:apply-templates select="item"/>
</ul>
</xsl:template>
<xsl:template match="item">
<xsl:variable name="Rows" select="channel/item"/>
<xsl:variable name="RowCount" select="count($Rows)"/>
<xsl:variable name="item_link" select="link"/>
<xsl:variable name="item_title" select="description"/>
<xsl:value-of select="$Rows"/>
<xsl:variable name="CurPosition" select="position()" />
<xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
<xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
<xsl:if test="not(substring(pubDate,3,9) = 0)">
<div align="center">
<hr/>
<xsl:value-of select="substring(pubDate,3,9)" disable-output-escaping="yes"/>
</div>
</xsl:if>
<li>
<a href="{$item_link}" title="{$item_title}">
<xsl:variable name="SafeHtml">
<xsl:call-template name="GetSafeHtml">
<xsl:with-param name="Html" select="title"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$SafeHtml" disable-output-escaping="yes"/>
</a>
</li>
</xsl:template>
<xsl:template name="GetSafeHtml">
<xsl:param name="Html"/>
<xsl:choose>
<xsl:when test="$rss_IsDesignMode = 'True'">
<xsl:value-of select="$Html"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="rssaggwrt:MakeSafe($Html)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
If you want to check the value of previous "row" you can use the preceding-sibling axis operator.
So, instead of writing this....
<xsl:if test="not(substring(pubDate,3,9) = 0)">
Write this...
<xsl:if test="not(substring(pubDate,3,9) = 0) and not(pubDate = preceding-sibling::item[1]/pubDate)">
Note the use of the [1] here. Doing preceding-sibling will return all nodes preceding the current one, and you only want the first one.
Also note, you might be tempted to write this...
<xsl:if test="not(substring(pubDate,3,9) = 0) and pubDate != preceding-sibling::item[1]/pubDate">
But this will not work for the first item element, because for that expression to be true the preceding sibling would have to exist.
Finally, this will only really work if the item elements are in pub-date order. A better approach would be to consider this a grouping problem, and group the items by date. For XSLT 1.0 you would use a technique called Muenchian Grouping.

Resources