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 8415023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:19:31+00:00 2026-06-10T01:19:31+00:00

This is a slightly updated question that was originally posted here: XSL – Finding

  • 0

This is a slightly updated question that was originally posted here: XSL – Finding another nodes value using the value of the current context .
I have an XML that uses PackageID values to reference other nodes in the document.

I want to create a for-each loop for each CompositionPackage that has the Operation value of ‘Rasta’. Note: a CompositionPackage can have more than one Match.
I would like to use the result of the current node to then find the value of another node containing the returned PackageID value in the document.
In this case I want to get the value of SourcePackage/PackageName or MaterialPackage/PackageName or another CompositionPackage that has a matching PackageID value to that found in CompositionPackage/PackageTracks/TimelineTrack/TrackSegment/SourcePackageID.

Sample XML:

<AAG version="1.1">
<Preface>
  <ContentStorage>
      <SourcePackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
                <ComponentLength>5066</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>Name001</PackageName>
        <PackageID>urn:44f70006</PackageID>
      </SourcePackage>
      <MaterialPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
            <ComponentLength>804</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>Name010</PackageName>
        <PackageID>urn:44f70008</PackageID>
      </MaterialPackage>
      <CompositionPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
                <Operation>Rasta</Operation>
                <SourcePackageID>urn:44f70006</SourcePackageID>
                <ComponentLength>10099</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
          <TimelineTrack>
            <TrackSegment>
                <Operation>NotRasta</Operation>
                <SourcePackageID>urn:44f70007</SourcePackageID>
                <ComponentLength>100</ComponentLength>
            </TrackSegment>
          <TimelineTrack>
            <TrackSegment>
                <Operation>Rasta</Operation>
                <SourcePackageID>urn:44f70008</SourcePackageID>
                <ComponentLength>200</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>NameABC</PackageName>
        <PackageID>urn:ce1904fd</PackageID>
      </CompositionPackage>
      <CompositionPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
                <Operation>Rasta</Operation>
                <SourcePackageID>urn:00f70009</SourcePackageID>
                <ComponentLength>222</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>NameABC</PackageName>
        <PackageID>urn:ff1603fd</PackageID>
      </CompositionPackage>
      <CompositionPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
                <Operation>Rasta</Operation>
                <SourcePackageID>urn:11f80008</SourcePackageID>
                <ComponentLength>444</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>NameBCD</PackageName>
        <PackageID>urn:gg1702fj</PackageID>
      </CompositionPackage>
      <CompositionPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
                <Operation>Rasta</Operation>
                <SourcePackageID>urn:22f90009</SourcePackageID>
                <ComponentLength>555</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>NameXYZ</PackageName>
        <PackageID>urn:11f80010</PackageID>
      </CompositionPackage>
      <CompositionPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
                <Operation>NotRasta</Operation>
                <SourcePackageID>urn:22f90009</SourcePackageID>
                <ComponentLength>555</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>NameWWW</PackageName>
        <PackageID>urn:11f80008</PackageID>
      </CompositionPackage>
      <MaterialPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
            <ComponentLength>864</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>Name008</PackageName>
        <PackageID>urn:00f70009</PackageID>
      </MaterialPackage>
      <MaterialPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
            <ComponentLength>864</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>Name002</PackageName>
        <PackageID>urn:22f70009</PackageID>
      </MaterialPackage>
  </ContentStorage>
</Preface>
</AAG>

Sample XSL:

<?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="no" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

 <xsl:template match = "AAG">
 <Master>
 <xsl:for-each select="AAG/Preface/ContentStorage/CompositionPackage/PackageTracks/TimelineTrack/TrackSegment/Operation"> <!--whose Operation value is 'Rasta' -->
 <newnode>
   <value1><xsl:value-of select ="CompositionPackage/PackageTracks/TimelineTrack/TrackSegment/ComponentLength"/></value1>
   <value2><xsl:value-of select ="CompositionPackage/PackageTracks/TimelineTrack/TrackSegment/SourcePackageID"/></value2>
   <value3><xsl:value-of select ="CompositionPackage/PackageTracks/TimelineTrack/TrackSegment[SourcePackageID=current()/MaterialPackage/PackageName"/></value3>
 </newnode>
 </xsl:for-each>
 </Master>
 </xsl:template>
 </xsl:stylesheet>

Expected XML:

<Master>
<newnode>
  <Value1>1099</Value1>
  <Value2>urn:44f70006</Value2>
  <Value3>Name001</Value3>
</newnode>
<newnode>
  <Value1>200</Value1>
  <Value2>urn:44f70008</Value2>
  <Value3>Name010</Value3>
</newnode>
<newnode>
  <Value1>222</Value1>
  <Value2>urn:00f70009</Value2>
  <Value3>Name008</Value3>
</newnode>
<newnode>
  <Value1>444</Value1>
  <Value2>urn:11f80008</Value2>
  <Value3>NameWWW</Value3>
</newnode>
<newnode>
  <Value1>555</Value1>
  <Value2>urn:22f90009</Value2>
  <Value3>Name002</Value3>
</newnode>
</Master>

My Current XSL is returning “” for all value3 elements.

  • 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-06-10T01:19:32+00:00Added an answer on June 10, 2026 at 1:19 am

    The error is obvious: inside a

    <xsl:for-each select=
    "AAG
      /Preface
        /ContentStorage
          /CompositionPackage
             /PackageTracks/TimelineTrack/TrackSegment/Operation">
    

    You have:

    <xsl:value-of select =
     "CompositionPackage/PackageTracks/TimelineTrack/TrackSegment/ComponentLength"/>
    

    As an Operation element doesn’t have any CompositionPackage children (and in fact doesn’t have any element children at all), the above selects nothing and nothing is output.

    Exactly the same case for the other two xsl:value-of instructions inside the body of xsl:for-each

    There are contradictions between the provided XML document and the wanted result and there are data errors:

    1. There isn’t any PackageID element with value “urn:22f90009”. Therefore, in the last newnode in the provided result, Value3 must be empty — but in the provided result it has a non-empty string value.

    2. In the source XML document there are nested TimelineTrack elements.

    These issues explain why the transformation I came up with doesn’t exactly produce the wanted result:

    <xsl:stylesheet version="1.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
          <xsl:strip-space elements="*"/>
    
          <xsl:template match="@*|node()">
                <xsl:copy>
                  <xsl:apply-templates select="@*|node()"/>
                </xsl:copy>
          </xsl:template>
    
          <xsl:template match = "AAG">
           <Master>
             <xsl:for-each select=
             "Preface
               /ContentStorage
                /CompositionPackage
                   /PackageTracks
                     /TimelineTrack
                       /TrackSegment[Operation='Rasta']
             ">
                 <newnode>
                   <value1>
                      <xsl:value-of select="ComponentLength"/>
                   </value1>
                   <value2>
                     <xsl:value-of select="SourcePackageID"/>
               </value2>
                   <value3>
                     <xsl:value-of select=
                      "../../../../*[self::SourcePackage
                           or self::MaterialPackage
                           or self::CompositionPackage]
                                        [PackageID
                                        =
                                        current()/SourcePackageID
                                        ]
                                        /PackageName
                         "/>
                   </value3>
                 </newnode>
           </xsl:for-each>
          </Master>
          </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

    <AAG version="1.1">
        <Preface>
            <ContentStorage>
                <SourcePackage>
                    <PackageTracks>
                        <TimelineTrack>
                            <TrackSegment>
                                <ComponentLength>5066</ComponentLength>
                            </TrackSegment>
                        </TimelineTrack>
                    </PackageTracks>
                    <PackageName>Name001</PackageName>
                    <PackageID>urn:44f70006</PackageID>
                </SourcePackage>
                <MaterialPackage>
                    <PackageTracks>
                        <TimelineTrack>
                            <TrackSegment>
                                <ComponentLength>804</ComponentLength>
                            </TrackSegment>
                        </TimelineTrack>
                    </PackageTracks>
                    <PackageName>Name010</PackageName>
                    <PackageID>urn:44f70008</PackageID>
                </MaterialPackage>
                <CompositionPackage>
                    <PackageTracks>
                        <TimelineTrack>
                            <TrackSegment>
                                <Operation>Rasta</Operation>
                                <SourcePackageID>urn:44f70006</SourcePackageID>
                                <ComponentLength>10099</ComponentLength>
                            </TrackSegment>
                        </TimelineTrack>
                        <TimelineTrack>
                            <TrackSegment>
                                <Operation>NotRasta</Operation>
                                <SourcePackageID>urn:44f70007</SourcePackageID>
                                <ComponentLength>100</ComponentLength>
                            </TrackSegment>
                            <TimelineTrack>
                                <TrackSegment>
                                    <Operation>Rasta</Operation>
                                    <SourcePackageID>urn:44f70008</SourcePackageID>
                                    <ComponentLength>200</ComponentLength>
                                </TrackSegment>
                            </TimelineTrack>
                        </TimelineTrack>
                    </PackageTracks>
                    <PackageName>NameABC</PackageName>
                    <PackageID>urn:ce1904fd</PackageID>
                </CompositionPackage>
                <CompositionPackage>
                    <PackageTracks>
                        <TimelineTrack>
                            <TrackSegment>
                                <Operation>Rasta</Operation>
                                <SourcePackageID>urn:00f70009</SourcePackageID>
                                <ComponentLength>222</ComponentLength>
                            </TrackSegment>
                        </TimelineTrack>
                    </PackageTracks>
                    <PackageName>NameABC</PackageName>
                    <PackageID>urn:ff1603fd</PackageID>
                </CompositionPackage>
                <CompositionPackage>
                    <PackageTracks>
                        <TimelineTrack>
                            <TrackSegment>
                                <Operation>Rasta</Operation>
                                <SourcePackageID>urn:11f80008</SourcePackageID>
                                <ComponentLength>444</ComponentLength>
                            </TrackSegment>
                        </TimelineTrack>
                    </PackageTracks>
                    <PackageName>NameBCD</PackageName>
                    <PackageID>urn:gg1702fj</PackageID>
                </CompositionPackage>
                <CompositionPackage>
                    <PackageTracks>
                        <TimelineTrack>
                            <TrackSegment>
                                <Operation>Rasta</Operation>
                                <SourcePackageID>urn:22f90009</SourcePackageID>
                                <ComponentLength>555</ComponentLength>
                            </TrackSegment>
                        </TimelineTrack>
                    </PackageTracks>
                    <PackageName>NameXYZ</PackageName>
                    <PackageID>urn:11f80010</PackageID>
                </CompositionPackage>
                <CompositionPackage>
                    <PackageTracks>
                        <TimelineTrack>
                            <TrackSegment>
                                <Operation>NotRasta</Operation>
                                <SourcePackageID>urn:22f90009</SourcePackageID>
                                <ComponentLength>555</ComponentLength>
                            </TrackSegment>
                        </TimelineTrack>
                    </PackageTracks>
                    <PackageName>NameWWW</PackageName>
                    <PackageID>urn:11f80008</PackageID>
                </CompositionPackage>
                <MaterialPackage>
                    <PackageTracks>
                        <TimelineTrack>
                            <TrackSegment>
                                <ComponentLength>864</ComponentLength>
                            </TrackSegment>
                        </TimelineTrack>
                    </PackageTracks>
                    <PackageName>Name008</PackageName>
                    <PackageID>urn:00f70009</PackageID>
                </MaterialPackage>
                <MaterialPackage>
                    <PackageTracks>
                        <TimelineTrack>
                            <TrackSegment>
                                <ComponentLength>864</ComponentLength>
                            </TrackSegment>
                        </TimelineTrack>
                    </PackageTracks>
                    <PackageName>Name002</PackageName>
                    <PackageID>urn:22f70009</PackageID>
                </MaterialPackage>
            </ContentStorage>
        </Preface>
    </AAG>
    

    the following result is produced:

    <Master>
        <newnode>
            <value1>10099</value1>
            <value2>urn:44f70006</value2>
            <value3>Name001</value3>
        </newnode>
        <newnode>
            <value1>222</value1>
            <value2>urn:00f70009</value2>
            <value3>Name008</value3>
        </newnode>
        <newnode>
            <value1>444</value1>
            <value2>urn:11f80008</value2>
            <value3>NameWWW</value3>
        </newnode>
        <newnode>
            <value1>555</value1>
            <value2>urn:22f90009</value2>
            <value3></value3>
        </newnode>
    </Master>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a slightly tricky question. I am using NSDateFormatter on the iPhone but
i know this has been asked here . But my question is slightly different.
Slightly related to this question , but you don't really need to read that.
slightly related to this question here . My problem: I am writing a bit
This question is slightly different from the kind of finding longest sequence or substring
First of all let me say that this questions is slightly connected to another
Apologies if this is a slightly noob question, but looking to clarify my thoughts
OK, this is a slightly weird question. We have a touch-screen application (i.e., no
I know that this is jumping the gun slightly as it is early days
I know this question has been done but I have a slightly different twist

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.