Hi Chris,
Please find below the solution to the problem
described by you -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan">
<xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>
<xsl:template match="/root">
<xsl:apply-templates select="GOP/content"/>
</xsl:template>
<xsl:template match="GOP/content">
<xsl:variable name="rtf">
<xsl:for-each select="*">
<xsl:if test="name() = 'A' ">
<A> <xsl:call-template
name="process-a1">
<xsl:with-param name="str" select="."/>
</xsl:call-template>
</A>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<header>
<size>
<xsl:value-of select="sum(xalan:nodeset($rtf)/A)"/>
</size>
</header>
<xsl:for-each select="*">
<xsl:if test="name() = 'A' ">
<A>
<xsl:call-template name="process-a2">
<xsl:with-param name="str" select="."/>
</xsl:call-template>
</A>
</xsl:if>
<xsl:if test="name() = 'B' ">
<xsl:copy-of select="." />
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="process-a1">
<xsl:param name="str"/>
<xsl:variable name="str1"
select="substring-after($str, ' ')"/>
<xsl:if test="$str1 < 10">
<xsl:value-of select="$str1 + 3"/>
</xsl:if>
<xsl:if test="not($str1 < 10)">
<xsl:value-of select="$str1"/>
</xsl:if>
</xsl:template>
<xsl:template name="process-a2">
<xsl:param name="str"/>
<xsl:variable name="str1"
select="substring-before($str, ' ')"/>
<xsl:variable name="str2"
select="substring-after($str, ' ')"/>
<xsl:value-of select="$str1" /><xsl:text>
</xsl:text>
<xsl:if test="$str2 < 10">
<xsl:value-of select="$str2 + 3"/>
</xsl:if>
<xsl:if test="not($str2 < 10)">
<xsl:value-of select="$str2"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
I have used the nodeset extension function, to do two
pass traversal of the XML by the stylesheet.
I added the <root> tag to make the XML well-formed.
Regards,
Mukul
--- poppe chris <pc_poppe(_at_)hotmail(_dot_)com> wrote: >
Hello, Im facing the following problem,
I have a xml file like this, in wich an A element
contains an offset (20,
30, 40) and a length (5, 10, 5) and the size element
in the header is the
sum of the lengths.
<header>
<size>20</size>
</header>
<GOP>
<content>
<A>20 5</A>
<B/>
<A>30 10</A>
<A>40 5</A>
<B/>
</content>
</GOP>
What i want to do is match any A element and alter
the length for example
everywhere + 3 except for lenghts greater then or
equal to 10. But the
problem is that I then have to change the size.
So the outputxml file should be:
<header>
<size>26</size>
</header>
<GOP>
<content>
<A>20 8</A>
<B/>
<A>30 10</A>
<A>40 8</A>
<B/>
</content>
</GOP>
I dont have a problem changing the A elements but i
do have a problem in
changing the size to the right number. Currently im
using 2 xsl files to
solve this, one to change the A elements and put the
changed length in an
helper element, this produces the following xml file
<header>
<size>20</size>
</header>
<GOP>
<content>
<A>20 8</A>
<help>8</help>
<B/>
<A>30 10</A>
<help>10</help>
<A>40 8</A>
<help>8</help>
<B/>
</content>
</GOP>
And then i use another xsl transformation to change
the size.
I would love to see all this happen in one xsl
transformation,
anyone got any idea's?
greetings,
Chris
_________________________________________________________________
Ben jij klaar voor De Vuilbek?
http://devuilbek.msn.be/start.php Nu op JIM
en MSN
--+------------------------------------------------------------------
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>
--+--
________________________________________________________________________
Yahoo! India Insurance Special: Be informed on the best policies, services,
tools and more.
Go to: http://in.insurance.yahoo.com/licspecial/index.html