[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Unable to pass a param variable to a template inside a
Hi, Problem: I am it seems unable to pass a param variable to a template inside a for each loop. Objective: I am trying to get the param to capture the position number of the node that is being processed in the for loop. So, each time it goes around the position() is being captured and inserted into the output XML as a new node. XSL Processor: Xalan 2.7 XSL Language: 1.0 Here is my XML input: <?xml version="1.0" encoding="UTF-8"?> <FileService> <Route>Reaper</Route> <File> <Filename>C:\datatrans\trans\outbound\texty1.txt</Filename> <ArchivePath>C:\datatrans\archive\outbound\</ArchivePath> <LogPath>C:\datatrans\confirmations\outbound\</LogPath> </File> <File> <Filename>C:\datatrans\trans\outbound\Texty2.txt</Filename> <ArchivePath>C:\datatrans\archive\outbound\</ArchivePath> <LogPath>C:\datatrans\confirmations\outbound\</LogPath> </File> <File> <Filename>C:\datatrans\trans\outbound\Word Doco.doc</Filename> <ArchivePath>C:\datatrans\archive\outbound\</ArchivePath> <LogPath>C:\datatrans\confirmations\outbound\</LogPath> </File> <File> <Filename>C:\datatrans\trans\outbound\Word.doc</Filename> <ArchivePath>C:\datatrans\archive\outbound\</ArchivePath> <LogPath>C:\datatrans\confirmations\outbound\</LogPath> </File> <Routing>SSI-F</Routing> <TransferProtocol> <Protocol>FTP</Protocol> <IP>127.0.0.1</IP> <Port>21</Port> <LoginName>username</LoginName> <Password>userpassword</Password> </TransferProtocol> <TransferQueue> <QueueName>Outbound</QueueName> <TransferJob>XferOut</TransferJob> </TransferQueue> </FileService> I have a style sheet (edited for this post) like so: <!-- Loops through the document to create <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"/> <!-- Java Service that is called --> <jbi:invoke service="foo:FileReaper"> <jbi:copyProperties/> <!-- the message sent to will be the result of this next call --> <xsl:apply-templates select="." mode="PickPosition"> <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="PickPosition"> <xsl:param name="posCtr2"/> <FileService> <xsl:copy-of select="Route"/> <xsl:copy-of select="Position"/> <!-- New node with param --> <PickPosition><xsl:value-of select="$posCtr"/></PickPosition> <xsl:copy-of select="File"/> <xsl:copy-of select="Routing"/> <xsl:copy-of select="TransferProtocol"/> <xsl:copy-of select="TransferQueue"/> </FileService> </xsl:template> The XML is being passed to the JAVA service for each File element (which means multiple times which is what I require) however the <PickPosition> element has no value on the output. If I force the line <xsl:param name="loopCtr"/> to read <xsl:param name="loopCtr select"12345"/> then I do get a 12345 output for the param and element. However I get nothing passed to the template with the for each line of <xsl:with-param name="loopCtr" select="position()"/>. Even if I force that with a dummy value like so <xsl:with-param name="loopCtr" select="99999"/> I still get no value! It seems unable to set and pass the loopCtr value to the ReaperMode template. All the rest seems to work. I must be missing something but as I understood it this is the way params worked :( 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 email once it has left our network.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|