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

  • Home
  • SEARCH
  • 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 186079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:35:03+00:00 2026-05-11T15:35:03+00:00

I need to use xsl/xpath (version 1.0) to do something special (for simplifying, say

  • 0

I need to use xsl/xpath (version 1.0) to do something special (for simplifying, say insert some dummy text) when the value of SupplierId changes. I need to handle 3 variations;

  1. Do something when on the first Order (the first occurence of SupplierId)
  2. Do somwthing when on OrderId O3 (SupplierId changed from S1 to S2)
  3. Do something when on the last Order (the last occurence of SupplierId)

.

<?xml version='1.0' encoding='utf-8'?> <Orders>     <Order>         <OrderId>O1</OrderId>         <SupplierId>S1</SupplierId>     </Order>     <Order>         <OrderId>O2</OrderId>         <SupplierId>S1</SupplierId>     </Order>     <Order>         <OrderId>O3</OrderId>         <SupplierId>S2</SupplierId>     </Order>     <Order>         <OrderId>O4</OrderId>         <SupplierId>S2</SupplierId>     </Order>     <Order>         <OrderId>O5</OrderId>         <SupplierId>S2</SupplierId>     </Order> </Orders> 

I’ve tried using preceding-sibling, following-sibling, etc, but haven’t found out of it yet. I’d appreciate any help on this newbie question.

Wally

  • 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. 2026-05-11T15:35:03+00:00Added an answer on May 11, 2026 at 3:35 pm

    This is one natural and easy solution:

    <xsl:stylesheet version='1.0'  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>  <xsl:output method='text'/>      <xsl:template match='Order[1]'>       First OrderId = <xsl:text/>       <xsl:value-of select='OrderId'/>     </xsl:template>      <xsl:template match='Order[last()]'>        Last OrderId = <xsl:text/>       <xsl:value-of select='OrderId'/>     </xsl:template>      <xsl:template match=       'Order[not(position() = 1)]          [not(SupplierId               =               preceding-sibling::Order[1]/SupplierId               )         ]'>        Changes in Order OrderId = <xsl:text/>       <xsl:value-of select='OrderId'/>          SupplierId = <xsl:text/>          <xsl:value-of select='SupplierId'/>       Previous Order OrderId = <xsl:text/>       <xsl:value-of select=         'preceding-sibling::Order[1]/OrderId'/>                  SupplierId = <xsl:text/>          <xsl:value-of select=          'preceding-sibling::Order[1]/SupplierId'/>     </xsl:template>      <xsl:template match='text()'/> </xsl:stylesheet> 

    When this transformation is applied on the provided XML document:

    <Orders>     <Order>         <OrderId>O1</OrderId>         <SupplierId>S1</SupplierId>     </Order>     <Order>         <OrderId>O2</OrderId>         <SupplierId>S1</SupplierId>     </Order>     <Order>         <OrderId>O3</OrderId>         <SupplierId>S2</SupplierId>     </Order>     <Order>         <OrderId>O4</OrderId>         <SupplierId>S2</SupplierId>     </Order>     <Order>         <OrderId>O5</OrderId>         <SupplierId>S2</SupplierId>     </Order> </Orders> 

    the desired result is produced:

      First OrderId = O1    Changes in Order OrderId = O3      SupplierId = S2   Previous Order OrderId = O2              SupplierId = S1    Last OrderId = O5 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use a datetime.strptime on the text which looks like follows. Some
I'd like to use the value of an xslt parameter in an xpath expression.
I am wondering if it is possible to use XPath or XSL to determine
I Need to create an XSL file so that I will use it to
I have a problem that I believe I need to use grouping using xsl:key
I'm new to XSLT. I know I need to use xsl:for-each-group, but I can't
I need to use sed to convert all occurences of ##XXX## to ${XXX} .
I need to use an alias in the WHERE clause, but It keeps telling
I need to use NSImage which appears need to be imported from <AppKit/AppKit.h> .
I need to use a many to many relationship in my project and since

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.