Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2011, 01:44 PM
Authorized User
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default xsl help

I have got the following xml in file_1

<in>
<document>
<content>
<fileName>doc11.txt</p52:fileName>
<contentSWA>941622958268</contentSWA>
</content>
</document>
<document xmlns:p52="http://travelers/content">
<content>
<fileName>doc22.txt</fileName>
<contentSWA>9574318958</contentSWA>
</content>
</document>
</in>

and in file_2
<
manifest>
<attachments>
<attachment>
<uri>cid:contentSWA=941622958268.1299148531514.IBM.WEBS ERVICES@drhiit09358</uri>
</attachment>
<attachment>
<uri>cid:contentSWA=9574318958.1299148531514.IBM.WEBSER VICES@drhiit09358</uri>
</attachment>
</attachments>
</
manifest>

i have the following in my xsl

<xsl:variable name="manifest" select="'file_2.xml'"/>
<xsl:template match="contentSWA">
<xsl:copy>
<xsl:copy-of select="*"/>
<xsl:for-each select="document($manifest//attachments)"><!-- process xml -->
</xsl:for-each>
</xsl:copy>
</xsl:template>

what i want to do is match the nth document/content/contentSWA ( in file_1) to the nth manifest/attachements/attachment(in file2). With my xsl for each document/content/contentSWA i'm processing all the attachements which i do not want to do . Could anyone let me know what i'm missing.

Thanks
 
Old March 3rd, 2011, 01:52 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Do you want to use XSLT 2.0 or 1.0? And what output do you want to create with your XSLT for the two samples you have posted?
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old March 3rd, 2011, 01:54 PM
Authorized User
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default

The output is in XML and i'm using xslt 2.0
 
Old March 3rd, 2011, 02:05 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

One way is to count the elements as in
Code:
  <xsl:template match="contentSWA">
    <xsl:variable name="pos" select="count(../../(., preceding-sibling::document))"/>
    <xsl:variable name="attachment" select="doc($manifest)/manifest/attachments/attachment[$pos]"/>
    <xsl:copy>
      <xsl:copy-of select="$attachment"/>
    </xsl:copy>
  </xsl:template>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old March 3rd, 2011, 02:11 PM
Authorized User
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thank you for the code. I would also like to know how to do it in XSLT 1.0
 
Old March 3rd, 2011, 02:15 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Code:
  <xsl:template match="contentSWA">
    <xsl:variable name="pos" select="count(../../preceding-sibling::document) + 1"/>
    <xsl:variable name="attachment" select="document($manifest)/manifest/attachments/attachment[$pos]"/>
    <xsl:copy>
      <xsl:copy-of select="$attachment"/>
    </xsl:copy>
  </xsl:template>
should do in XSLT 1.0.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
nguna (March 3rd, 2011)
 
Old March 3rd, 2011, 02:17 PM
Authorized User
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thank you very much





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:function pass param to attribute of xsl:instruction bonekrusher XSLT 4 March 31st, 2009 09:06 AM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
differnce between xsl:apply-templates and xsl:call chandu.mca007 XSLT 2 June 12th, 2007 04:12 AM
xsl advise needed - Replacing UID through XSL Billyl XSLT 6 February 28th, 2006 05:46 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.