I use XSLT and XML.
I have below XML with me.
<?xml version="1.0" encoding="UTF-8"?>
<mappings>
<mapping old="mbp" new="/SessionHandler.aspx?pageurl=/BP.aspx&pub=/english&section=IBE&j=f"/>
<mapping old="about/news" new="about/news/news.aspx"/>
<mapping old="/nhs" new="/cugo.aspx?promoCode=UKNHS01&pub=/uk/english"/>
<mapping old="/hk/ukstudentfare" new="/cugo.aspx?promoCode=HKSTU10&pub=/hk/Chinese"/>
<mapping old="/kgfmastercard" new=""/>
<mapping old="/mastercard" new=""/>
<mapping old="/destinationbriefs" new="http://www.ekgroup.com/destinationbriefs"/>
<mapping old="/win" new="/ch/german/destinations_offers/win_two_tickets_on_A380.aspx"/>
<mapping old="/romefanfest" new="/it/italian/destinations_offers/rome_international_fifa_fan_fest.aspx"/>
<mapping old="/parisfanfest" new="/fr/french/destinations_offers/paris_international_fifa_fan_fest.aspx"/>
</mappings>
Below xslt I use
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="xsl fo">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:for-each select="mappings/mapping">
<VanityUrl>
<old>
<xsl:value-of select="@old" />
</old>
<new>
<xsl:value-of select="@new" />
</new>
<dateAdded>2010-05-03T14:45:00</dateAdded>
<xsl:if test="@new = ''">
<NotLive>Yes</NotLive>
</xsl:if>
<xsl:if test="preceding-sibling::comment()">
<comments>
<xsl:value-of select="preceding-sibling::comment()" />
</comments>
</xsl:if>
</VanityUrl>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Now I am trying to get the result as shown below:
<VanityUrl>
<old>/mbp</old>
<new>/SessionHandler.aspx?pageurl=/BP.aspx&pub=/english&section=IBE&j=f</new>
<dateAdded>2010-05-03T14:45:00 </dateAdded>
<comment>News mapping</comments>
</VanityUrl>
<VanityUrl>
<old>about/news</old>
<new>about/news/news.aspx</new>
<dateAdded>2010-05-03T14:45:00 </dateAdded>
<comment>News mapping</comments>
</VanityUrl>
<VanityUrl>
<old>/nhs</old>
<new>/cugo.aspx?promoCode=UKNHS01&pub=/uk/english</new>
<dateAdded>2010-05-03T14:45:00 </dateAdded>
<comment>CUGO's</comments>
</VanityUrl>
<VanityUrl>
<old>/hk/ukstudentfare</old>
<new>/cugo.aspx?promoCode=HKSTU10&pub=/hk/Chinese</new>
<dateAdded>2010-05-03T14:45:00 </dateAdded>
<comment>CUGO's</comments>
</VanityUrl>
<VanityUrl>
<old>/kgfmastercard</old>
<new></new>
<NotLive>yes</NotLive>
<dateAdded>2010-05-03T14:45:00 </dateAdded>
<comment>Reserved below vanity URL's</comments>
</VanityUrl>
<VanityUrl>
<old>/mastercard</old>
<new></new>
<NotLive>yes</NotLive>
<dateAdded>2010-05-03T14:45:00 </dateAdded>
<comment>Reserved below vanity URL's</comments>
</VanityUrl>
Everything is in order, but I canβt work with the comment section, how to add comment elements according to the corresponding comments. I mean that below the code in my xslt does not work correctly, adding only the first comment, i.e. News Display
xsl:if test="preceding-sibling::comment()">
<comments>
<xsl:value-of select="preceding-sibling::comment()" />
</comments>
</xsl:if>
source
share