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 August 12th, 2008, 05:15 PM
Authorized User
 
Join Date: Dec 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL Iteration problems

I am having troubles reading the second value from the loop. Always gets the first one. I tried using Nodes with no success. Also tried using Param by setting value. still buggy.Any input is appreciated.
I am posting the initial XSLT, so that the gurus get me the right function available in XSLT, rather param route

Input XML
<?xml version="1.0" encoding="utf-8"?>
<ns:InventorySync xmlns:ns="http://anthing.com/anything">
    <ELC>
        <SYSINF>OMSORDR OEXXB70 SAPD02 1234567890D000000045020080807123642VER</SYSINF>
    </ELC>
    <ELC>
        <SYSINF>ELC order Number OMS order number OE Order Error occurence</SYSINF>
    </ELC>
</ns:InventorySync>


XSLT:

<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">

    <ELC>
    <xsl:for-each select="//ELC">
    <xsl:choose>
                    <xsl:when test="substring(//ELC/SYSINF, 1, 7)='OMSORDR'">
                        <SYSINF><xsl:value-of select="//SYSINF"/></SYSINF>
                    </xsl:when>
                    <xsl:otherwise>
                        <ORDERRSPHDR1><xsl:value-of select="//SYSINF"/></ORDERRSPHDR1>
                    </xsl:otherwise>
                </xsl:choose>
    </xsl:for-each>
    </ELC>
    </xsl:template>
</xsl:stylesheet>

Trying to get output something like below
<ELC><SYSINF>OMSORDR OEXXB70 SAPD02 1234567890D000000045020080807123642VER</SYSINF><ORDERRSPHDR1>ELC order Number OMS order number OE Order Error occurence </ORDERRSPHDR1></ELC>

 
Old August 12th, 2008, 05:34 PM
Authorized User
 
Join Date: Dec 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I did solve problem myself. Thanks a bunch

<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
    <ELC>
                        <SYSINF><xsl:value-of select="//ELC[1]/SYSINF"/></SYSINF>
                        <ORDERRSPHDR1><xsl:value-of select="//ELC[2]/SYSINF"/></ORDERRSPHDR1>
    </ELC>
    </xsl:template>
</xsl:stylesheet>

 
Old August 12th, 2008, 07:16 PM
Authorized User
 
Join Date: Dec 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One more question on same XSL

I am trying to print 1&2 in different Tags , and from 3 to End will printing into Different tag. I took the position, that loops through perfect, while printing i am not getting that value. XML Input is almost same, it repeats several times, it could be N everytime.
Any help is appreciated

<SYSINF><xsl:value-of select="//ELC[1]/SYSINF"/></SYSINF>
                        <INVSYNHEAD><xsl:value-of select="//ELC[2]/SYSINF"/></INVSYNHEAD>
                        <xsl:for-each select="//ELC">
                         <xsl:if test="position() > 2">
                        <INVSYNDATA><xsl:value-of select="ELC[position()]/SYSINF"/></INVSYNDATA>
                        </xsl:if>
                           </xsl:for-each>

 
Old August 12th, 2008, 08:17 PM
Authorized User
 
Join Date: Dec 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I solved this problem as well. Appreciated for all spending your time on this post
Replaced ELC[position()] with "." from the following line and it worked like a charm
<INVSYNDATA><xsl:value-of select="./SYSINF"/></INVSYNDATA>






Similar Threads
Thread Thread Starter Forum Replies Last Post
problems with excel generated usng xsl a_gomathi XSLT 5 May 29th, 2008 01:30 PM
XSL(T) problems with xsl:element pan69 XSLT 3 December 13th, 2007 06:24 AM
Problems passing xsl parameters from javascript mxxz XSLT 4 November 3rd, 2006 11:21 AM
Problems using <xsl:import in web app flanagaj XSLT 0 April 18th, 2006 08:40 AM
hello, some problems with XSL-FO LuisMM XSLT 4 December 19th, 2003 02:55 PM





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