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 October 8th, 2004, 07:04 AM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I get Data from the previous node?

Hi,


The node structure is "SRT/FTX2" and "SRT/GID", both are childs of "SRT". The "FTX2" child needs to be mapped inside the "GID" child, so it is called from there when the dommapping runs. But, it is possible that the "FTX2" child does not exsist. Then the previous "FTX2" information needs to be mapped in the current "GID" child. Can anyone offer some assistance?

XSL stylesheet sofar:

<xsl:apply-templates select="PIA"/>

        <xsl:choose>
            <xsl:when test="not(../FTX2)">
                <FTX>
                <dommapper:inc name="segment_count"/>
                <xsl:variable name="SRT1"><xsl:value-of select="../SRT1"/></xsl:variable>
                <xsl:variable name="SRT3"><xsl:value-of select="../SRT3"/></xsl:variable>

                <xsl:variable name="v4451"><xsl:value-of select="./FTX2/FTX4451"/></xsl:variable>
                <dommapper:log msg="$v4451"/>

                <xsl:variable name="v44511"><xsl:copy-of select="./FTX2/FTX4451"/></xsl:variable>
                <dommapper:log msg="$v44511"/>

                <dommapper:log msg="in not_test"/>
                <dommapper:log msg="$SRT1"/>
                <dommapper:log msg="$SRT3"/>

                    <ElementsFTX>
                        <S4451><xsl:copy-of select="../FTX2/FTX4451"/></S4451>
                        <S4453><xsl:copy-of select="../FTX2/FTX4453"/></S4453>
                        <CC107>
                            <S4441/>
                        </CC107>
                        <CC108>
                            <S4440><xsl:copy-of select="../FTX2/FTX4440"/></S4440>
                            <S4440><xsl:copy-of select="SRT[SRT1=$SRT1 and SRT3=$SRT3]/FTX2/FTX4440-2"/></S4440>
                            <S4440><xsl:copy-of select="SRT[SRT1=$SRT1 and SRT3=$SRT3]/FTX2/FTX4440-3"/></S4440>
                            <S4440><xsl:copy-of select="SRT[SRT1=$SRT1 and SRT3=$SRT3]/FTX2/FTX4440-4"/></S4440>
                            <S4440><xsl:copy-of select="SRT[SRT1=$SRT1 and SRT3=$SRT3]/FTX2/FTX4440-5"/></S4440>
                        </CC108>
                        <S3453><xsl:copy-of select="SRT[SRT1=$SRT1 and SRT3=$SRT3]/FTX2/FTX3453"/></S3453>
                    </ElementsFTX>
                </FTX>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="../FTX2"/>
            </xsl:otherwise>
        </xsl:choose>

        <xsl:apply-templates select="FTX4"/>


XML input :

<SRT>
        <SRT1>357N0</SRT1>
        <SRT2>0</SRT2>
        <SRT3>2VH</SRT3>
        <FTX2>
         <FTX4451>PAC</FTX4451>
         <FTX4440>Ref. ABEC : 94357</FTX4440>
         <FTX3453>EN</FTX3453>
         <FTX4453>1</FTX4453>
        </FTX2>
        <FTX2>
         <FTX4451>PAC</FTX4451>
         <FTX4440>AGML</FTX4440>
         <FTX3453>EN</FTX3453>
         <FTX4453>1</FTX4453>
        </FTX2>
        <FTX2>
         <FTX4451>PAC</FTX4451>
         <FTX4440>DUBAI</FTX4440>
         <FTX3453>EN</FTX3453>
         <FTX4453>1</FTX4453>
        </FTX2>
        <FTX2>
         <FTX4451>PAC</FTX4451>
         <FTX4440>Made in BELGIUM</FTX4440>
         <FTX3453>EN</FTX3453>
         <FTX4453>1</FTX4453>
        </FTX2>
        <FTX2>
         <FTX4451>AAA</FTX4451>
         <FTX4440>MAGNETIC TAPES</FTX4440>
         <FTX3453>EN</FTX3453>
         <FTX4453>1</FTX4453>
        </FTX2>
        <GID>
         <GID1496>1</GID1496>
         <GID7224-1>00000000</GID7224-1>
         <GID7065-1>CT</GID7065-1>
         <GID7224-3>00000002</GID7224-3>
         <GID7065-3>BY</GID7065-3>
         <MEA>



Thx
 
Old October 8th, 2004, 08:07 AM
Authorized User
 
Join Date: Jul 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would try simplifying your example and explain your required output.
Your example code is difficult to follow.

Regards
Bryan



 
Old October 9th, 2004, 02:36 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

To get the previous node information you can use ascestor::nodename or preceding-sibling::nodename.Try it out.
Check this link for more information on axes
http://www.w3.org/TR/xpath#axes

You example code is difficult to follow as Bryan said.

 
Old October 11th, 2004, 08:01 AM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, a quick update :

this is the code from my stylesheet so far :
    <dommapper:inc name="segment_count"/>
                <xsl:variable name="SRT1"><xsl:value-of select="../SRT1"/></xsl:variable>
                <xsl:variable name="SRT3"><xsl:value-of select="../SRT3"/></xsl:variable>

                <xsl:variable name="P_SRT1"><xsl:value-of select="../../SRT/SRT1"/></xsl:variable>
                <xsl:variable name="P_SRT3"><xsl:value-of select="../../SRT/SRT3"/></xsl:variable>

                <xsl:variable name="v4451"><xsl:value-of select="../../SRT[($P_SRT1=$SRT1) and ($P_SRT3=$SRT3)]/FTX2[FTX4451 = 'AAA']/FTX4451"/></xsl:variable>



I'll explain a bit. I have the following node structure (or input xml, whatever you want to call it) :
<SRT>
<ElementsSRT>
<SRT1>
<SRT2>
<SRT3>
</ElementsSRT>
<GID>
</GID>
<FTX2>
</FTX2>
</SRT>

Now what I need to accomplish is the following. Sometimes the SRT doesnt have a FTX child. If this happens, I need to go back to the previous SRT with the correct qualifier and fill the current FTX up with data from that FTX. The qualifiers are in the SRT1 and SRT3 fields. Thus I get the construction : <xsl:variable name="v4451"><xsl:value-of select="../../SRT[($P_SRT1=$SRT1) and ($P_SRT3=$SRT3)]/FTX2[FTX4451 = 'AAA']/FTX4451"/></xsl:variable>. The only problem I now face is that when I use this construction, he goes up one level, but he keeps going to the VERY FIRST SRT node and not the previous as is demanded.

Imagine a row of 5 items. I'm inside the 3rd item, but I lack information, so I check to see if the item before me, the second item (via SRT1 and SRT3, which I compare to my SRT1 and SRT3 from the item I'm in, the 3rd) has the information required. The preceding item will always have the required information! Instead my test now goes back to the first item, checks and even when the check is false, gives me the information from that item. I'm very close to solving it, but I can't grasp that final thingy :-) I hope this explains it better?

The output needs to be:
<GID>
...some tags
<FTX2></FTX2>
...some tags
</GID>

The output is not the issue here, it is getting the right information to create the output.
 
Old October 12th, 2004, 02:49 AM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The core of the problem is : If there is NO SRT/FTX2 node, go back to the previous SRT/FTX2 and use the information stored here. Can anyone please help me with this problem? It looks simpel enough, but I cannot put my finger on it.

 
Old October 13th, 2004, 03:55 AM
Authorized User
 
Join Date: Jul 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You must realise that this is a help forum and the most members do not have the time to look though and understand your xml structure, especially when your explanations do not always match it.

If you require help you must simplify your examples or you will be lucky to get any responses.

That said - the correct method of referencing a "previous sibling" is by using the preceding-sibling axis, this axis returns the previous nodes (note "nodes") in reverse order. This is a little confusing perhaps the axis should have been called preceding-siblings.

Anyhow, the real "previous sibling" is therefore referenced by preceding-sibling::*[1]

For example:
<xsl:template match="SRT">
  <xsl:if test="not(FTX)">
    <xsl:value-of select="preceding-sibling::SRT[1]/FTX" />
  </xsl:if>

..
..

Regards
Bryan








Similar Threads
Thread Thread Starter Forum Replies Last Post
How to store the previous node value Neha XSLT 3 July 23rd, 2008 05:42 AM
Compare current value with previous parent node ratjetoes XSLT 2 July 17th, 2008 06:15 AM
Missing Node (Node data) pashworth XSLT 3 January 29th, 2007 12:39 PM
Show fields depending on data entered in previous Vaz ASP.NET 2.0 Basics 0 June 27th, 2006 09:16 AM
Extract Data From Node ryanpatrick XML 1 February 18th, 2004 10:31 AM





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