Thanks Ramon,
That worked a treat.
However for some reason I seem unable to pass a param in the for loop.
For example I wish to stick the number of the counter in the node.
So, each InsertedNode value is different by position number it got executed by template in the loop.
Thus I would have several documents the same except there will be different values in the <InsertedNode> element like so:
First loop stage for document copy:
<InsertedNode>1</InsertedNode>
Second loop stage for document copy 1:
<InsertedNode>2</InsertedNode>
Third loop stage for document copy 1:
<InsertedNode>3</InsertedNode>
Forth loop stage for document copy 1:
<InsertedNode>4</InsertedNode>
......
And so on.
My params seem to work in other templates (when I hardcode some value to them) but not when I add it to the for loop like so:
<xsl:with-param name="loopCtr" select="position()"/>
My XSL is as follows:
<!-- Forward the service to the reaper service by number of files -->
<xsl:when test="FileService/Route='Reaper'">
<xsl:for-each select="FileService/File">
<xsl:apply-templates select="/" mode="ReaperMode">
<xsl:with-param name="loopCtr" select="position()"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:when>
<!-- Match the the whole of the document for invoking the FileReaper -->
<xsl:template match="FileService" mode="ReaperMode">
<xsl:param name="loopCtr"/>
<jbi:invoke service="foo:FileReaper">
<jbi:copyProperties/>
<!-- the message sent to will be the result of this next call -->
<xsl:apply-templates select="." mode="InsertedNode">
<xsl:with-param name="posCtr2" select="$loopCtr"/>
</xsl:apply-templates>
</jbi:invoke>
</xsl:template>
<!-- Rebuild the document by the template adding the Pick Position -->
<xsl:template match="FileService" mode="InsertedNode">
<xsl:param name="posCtr2"/>
<FileService>
<xsl:copy-of select="Route"/>
<InsertedNode><xsl:value-of select="$posCtr2"/></InsertedNode>
<xsl:copy-of select="File"/>
</FileService>
</xsl:template>
Regards Rick
"Ramon Buckland" <[EMAIL PROTECTED]>
07/04/2006 03:37 | To: <[email protected]> cc: Subject: RE: problem inserting node using XSL with JBI invoke |
Hi Rick,
This is what you would be looking for.
Regards
Ramon
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:jbi="xalan://org.apache.servicemix.components.xslt.XalanExtension"
extension-element-prefixes="jbi"
xmlns:foo="http://servicemix.apache.org/demo/"
exclude-result-prefixes="foo"
version="1.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8" />
<xsl:template match="/">
<xsl:apply-templates select="FileService[Route='Reaper']"
mode="ReaperMode"/>
</xsl:template>
<xsl:template match="FileService" mode="ReaperMode">
<!-- Invoke the reaper service -->
<jbi:invoke service="foo:trace">
<jbi:copyProperties/>
<!-- the message sent to foo:trace will be the result of this
next call -->
<xsl:apply-templates select="." mode="InsertNode"/>
</jbi:invoke>
</xsl:template>
<xsl:template match="FileService" mode="InsertNode">
<FileService>
<xsl:copy-of select="Route"/>
<InsertedNode>2</InsertedNode>
<xsl:copy-of select="File"/>
</FileService>
</xsl:template>
</xsl:stylesheet>
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, 7 April 2006 2:02 AM
To: [email protected]
Subject: problem inserting node using XSL with JBI invoke
Using the following XML:
<?xml version="1.0" encoding="UTF-8"?><FileService>
<Route>Reaper</Route>
<File>
<Filename>C:\datatrans\test\trans\outbound\texty1.txt</Filename>
</File>
<File>
<Filename>C:\datatrans\test\trans\outbound\texty2.txt</Filename>
</File>
</FileService>
And this XSL stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:jbi="xalan://org.apache.servicemix.components.xslt.XalanExtension"
extension-element-prefixes="jbi"
xmlns:foo="http://servicemix.apache.org/demo/"
version="1.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8" />
<xsl:template match="/">
<xsl:choose>
<!-- Invoke the reaper service -->
<xsl:when test="FileService/Route='Reaper'">
<xsl:for-each select="FileService/File">
<jbi:invoke service="foo:FileReaper">
<jbi:copyProperties/>
<xsl:copy-of select="/"/>
</jbi:invoke>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<jbi:copyProperties/>
<jbi:forward service="foo:trace"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
I cannot seem to insert a node anywhere in the document.
Ideally I would like to insert a node just after the Route node, like so:
<?xml version="1.0" encoding="UTF-8"?>
<FileService>
<Route>Reaper</Route>
<InsertedNode>2</InsertedNode>
<File>
<Filename>C:\datatrans\test\trans\outbound\texty1.txt</Filename>
</File>
<File>
<Filename>C:\datatrans\test\trans\outbound\texty10.txt</Filename>
</File>
<File>
<Filename>C:\datatrans\test\trans\outbound\test1.doc</Filename>
</File>
</FileService>
I have tried using an <xsl:element tag but to no avail. It seems to just
disrupt the output and give me errors. But the XSL as it is now does work
without my inserted node so, is it the XalanExtension not working or more
likely what is the XSL to do it?
Regards Rick
Direct Line Group Limited, registered in England
with number 2811437, registered office 3 Edridge
Road, Croydon, Surrey CR9 1AG. The following
companies are members of the Direct Line Group:
Direct Line Insurance plc, Direct Line Life
Insurance Company Limited, Direct Line Unit
Trusts Limited and Direct Line Financial Services
Limited, all of which are authorised and regulated
by the Financial Services Authority. All are
members of The Royal Bank of Scotland Group.
This email is intended for the addressee only and
may contain confidential, proprietary or legally
privileged information. If you are not the
intended recipient of this email you should
notify us immediately and delete it. You should
not copy, print, distribute, disclose or use any
part of it. We reserve the right to monitor and
record all electronic communications through our
networks. We cannot accept any liability for
viruses transmitted via this e-mail once it has
left our networks.
Direct Line Group Limited, registered in England with number 2811437, registered office 3 Edridge Road, Croydon, Surrey CR9 1AG. The following companies are members of the Direct Line Group: Direct Line Insurance plc, Direct Line Life Insurance Company Limited, Direct Line Unit Trusts Limited and Direct Line Financial Services Limited, all of which are authorised and regulated by the Financial Services Authority. All are members of The Royal Bank of Scotland Group. |
This email is intended for the addressee only and may contain confidential, proprietary or legally privileged information. If you are not the intended recipient of this email you should notify us immediately and delete it. You should not copy, print, distribute, disclose or use any part of it. We reserve the right to monitor and record all electronic communications through our networks. We cannot accept any liability for viruses transmitted via this e-mail once it has left our networks. |
