Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6232827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:11:13+00:00 2026-05-24T10:11:13+00:00

XSLT How to get previous attribute value if my condition satisfied? I have tried

  • 0

XSLT How to get previous attribute value if my condition satisfied?

I have tried to get the desired out but not succeeded can someone please assist me how to achieve this?

Here is my Zip.xml

<Zip>
        <ZipNotify Zip="1144" ZipNo="1" ZipTime="2010-09-02T11:15:30+10:00"/>
        <ZipDetail Zone="U" DepartZip="West" ArriveZip="West"/>
        <ZipCategoryDetail ZORE="false" />
        <ZipOrigin ZipOrigin="ABC002" Die="20:59:00"/>
        <ZipDestination ZipDestination="UVW001" Live="21:38:00"/>
        <ZipPath>
            <ZipSubject ZipSubjectType="Payed" ZipNum="1">
                <ZipRoute ZipLoc="ABC002" ZipStop="true" ZipDieTime="20:59:00" ZipDieTime1="20:59:00"/>
            </ZipSubject>
            <ZipSubject ZipSubjectType="Payed" ZipNum="2">
                <ZipRoute ZipLoc="BCD002" ZipStop="true" ZipLiveTime="21:00:40" ZipDieTime1="21:01:00"/>
                <ZipSpec Charge="false"/>
            </ZipSubject>
            <ZipSubject ZipSubjectType="Payed" ZipNum="3">
                <ZipRoute ZipLoc="CDE001" ZipStop="true" ZipLiveTime="21:03:40" ZipDieTime1="21:04:00"/>
                <ZipSpec Charge="true"/>
            </ZipSubject>
            <ZipSubject ZipSubjectType="Payed" ZipNum="4">
                <ZipRoute ZipLoc="DEF001" ZipStop="true" ZipLiveTime="21:05:40" ZipDieTime1="21:06:00"/>
                <ZipSpec Charge="true"/>
            </ZipSubject>
            <ZipSubject ZipSubjectType="Payed" ZipNum="5">
                <ZipRoute ZipLoc="EFG001" ZipStop="true" ZipLiveTime="21:07:40" ZipDieTime1="21:08:00"/>
                <ZipSpec Charge="true"/>
            </ZipSubject>
            <ZipSubject ZipSubjectType="Payed" ZipNum="5">
                <ZipRoute ZipLoc="UVW001" ZipStop="true" ZipLiveTime="21:38:00" ZipLiveTime1="21:38:00"/>
                <ZipSpec Charge="true"/>
            </ZipSubject>
        </ZipPath>
</Zip>

Here is my XSL

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
    <head/>
        <body>
            <xsl:for-each select="/Zip/ZipPath/ZipSubject">
                <xsl:if test="/Zip/ZipPath/ZipSubject/ZipSpec/@Charge = 'true'">
                    <div>ZipLoc: <xsl:value-of select="/Zip/ZipPath/ZipSubject/ZipRoute/@ZipLoc"/> </div>
                    <div>Charge: <xsl:value-of select="/Zip/ZipPath/ZipSubject/ZipSpec/@Charge"/></div>
                </xsl:if>

            </xsl:for-each>
        </body>
    </html>
    </xsl:template>
</xsl:stylesheet>

Out Put I want is
I want to get the ZipLoc of previous ZipSubject where Charge=”true”
Eg. For ZipNum=”3″ value Charge=”true” so my out put must display previous ZipLoc=”BCD002″ (even though Charge=”false” ZipNum=”2″) that’s it, it should not do further validation for ZipOrigin and for ZipDestination again it should check from the last ZipNum=”5″ if Charge=”true” then simply it should use the same ZipLoc=”UVW001″

Desired Output should be

BCD002UVW001

But my output is below. I have tried possible ways(I know its lack of experience with XSLT which is not an excuse) please help me to get the Desired Output

ZipLoc: ABC002
Charge: false
ZipLoc: ABC002
Charge: false
ZipLoc: ABC002
Charge: false
ZipLoc: ABC002
Charge: false
ZipLoc: ABC002
Charge: false
ZipLoc: ABC002
Charge: false
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:11:14+00:00Added an answer on May 24, 2026 at 10:11 am

    I want to get the ZipLoc of previous ZipSubject where Charge=”true”

    Inside the context of xsl:for-eachyou can use the following XPath:

     "preceding-sibling::ZipSubject[1]/ZipRoute/@ZipLoc"
    

    E.g, the following XSLT fragment show how to print ZipLog and Charge of preceding node only for those with Charge=’true’:

    <xsl:for-each select="/Zip/ZipPath/ZipSubject[ZipSpec/@Charge = 'true']">
      <div>ZipLoc: <xsl:value-of 
           select="preceding-sibling::ZipSubject[1]/ZipRoute/@ZipLoc"/> 
      </div>
      <div>Charge: <xsl:value-of 
           select="preceding-sibling::ZipSubject[1]/ZipSpec/@Charge"/></div>
    </xsl:for-each>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm editing an XSLT 2.0 document in emacs and get an attribute value invalid
I have an attribute: <names>Dan,John,Matin,Lewis</names> Can you create a filter [names='Dan'] and get the
I'm new to XSLT and I can't figure out how to get an xsl:if
Question Using XSLT 1.0, given a string with arbitrary characters how can I get
What is the XSLT to get a parent node based on the value of
How to use xsl:for-each in xslt to get value iteratively from an xml file
I have some xslt that uses a c# function to get a string, im
In XSLT there is the <xsl:value-of select=expression/> to get the value of an element,
In any language, XSLT , PHP, Ruby, Perl, anything: how can I get the
I'm not an XSLT wizard. I have the current XSLT i'm using to remove

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.