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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:15:56+00:00 2026-06-09T22:15:56+00:00

I have an XML that uses PackageID values to reference other nodes in the

  • 0

I have an XML that uses PackageID values to reference other nodes in the document.
I would like to use the result of the current node to then find the value of another node containing the matching PackageID 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>
      <CompositionPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
                <SourcePackageID>urn:44f70006</SourcePackageID>
                <ComponentLength>10099</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>NameABC</PackageName>
        <PackageID>urn:ce1904fd</PackageID>
      </CompositionPackage>
      <CompositionPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
                <SourcePackageID>urn:00f70009</SourcePackageID>
                <ComponentLength>222</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>NameABC</PackageName>
        <PackageID>urn:ff1603fd</PackageID>
      </CompositionPackage>
      <CompositionPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
                <SourcePackageID>urn:11f80008</SourcePackageID>
                <ComponentLength>444</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>NameBCD</PackageName>
        <PackageID>urn:gg1702fj</PackageID>
      </CompositionPackage>
      <CompositionPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
                <SourcePackageID>urn:22f90009</SourcePackageID>
                <ComponentLength>555</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>NameXYZ</PackageName>
        <PackageID>urn:11f80008</PackageID>
      </CompositionPackage>
      <MaterialPackage>
        <PackageTracks>
          <TimelineTrack>
            <TrackSegment>
            <ComponentLength>864</ComponentLength>
            </TrackSegment>
          </TimelineTrack>
        </PackageTracks>
        <PackageName>Name002</PackageName>
        <PackageID>urn:00f70009</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">
 <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>222</Value1>
  <Value2>urn:00f70009</Value2>
  <Value3>Name002</Value3>
</newnode>
<newnode>
  <Value1>444</Value1>
  <Value2>urn:11f80008</Value2>
  <Value3>NameXYZ</Value3>
</newnode>
<newnode>
  <Value1>555</Value1>
  <Value2>urn:22f90009</Value2>
  <Value3></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-09T22:15:57+00:00Added an answer on June 9, 2026 at 10:15 pm

    The provided transformation has several errors.

    The transformation below is the provided one with the errors corrected:

     <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">
             <newnode>
               <value1>
                  <xsl:value-of select=
                    "PackageTracks/TimelineTrack/TrackSegment/ComponentLength"/>
               </value1>
               <value2>
                 <xsl:value-of select=
                  "PackageTracks/TimelineTrack/TrackSegment/SourcePackageID"/>
           </value2>
               <value3>
                 <xsl:value-of select=
                  "../*[self::SourcePackage or self::MaterialPackage]
                                    [PackageID
                                    =
                                    current()
                                     /PackageTracks/TimelineTrack/TrackSegment/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>
                <CompositionPackage>
                    <PackageTracks>
                        <TimelineTrack>
                            <TrackSegment>
                                <SourcePackageID>urn:44f70006</SourcePackageID>
                                <ComponentLength>10099</ComponentLength>
                            </TrackSegment>
                        </TimelineTrack>
                    </PackageTracks>
                    <PackageName>NameABC</PackageName>
                    <PackageID>urn:ce1904fd</PackageID>
                </CompositionPackage>
                <CompositionPackage>
                    <PackageTracks>
                        <TimelineTrack>
                            <TrackSegment>
                                <SourcePackageID>urn:00f70009</SourcePackageID>
                                <ComponentLength>222</ComponentLength>
                            </TrackSegment>
                        </TimelineTrack>
                    </PackageTracks>
                    <PackageName>NameABC</PackageName>
                    <PackageID>urn:ff1603fd</PackageID>
                </CompositionPackage>
                <MaterialPackage>
                    <PackageTracks>
                        <TimelineTrack>
                            <TrackSegment>
                                <ComponentLength>864</ComponentLength>
                            </TrackSegment>
                        </TimelineTrack>
                    </PackageTracks>
                    <PackageName>Name002</PackageName>
                    <PackageID>urn:00f70009</PackageID>
                </MaterialPackage>
            </ContentStorage>
        </Preface>
    </AAG>
    

    the wanted, correct 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>Name002</value3>
       </newnode>
    </Master>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a source xml document that uses namespace containing prefixes and a default namespace.
I have a Clojure project that I would like to package and use in
I have been assigned to implement an interface to an API that uses XML
I have some code that uses Open XML to open up a .docx file,
I have a asp.net web forms app that uses System.Web.Caching.Cache to cache xml data
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have XML that looks like this: <ROW ref=0005631 type=04 line=1 value=Australia/> <ROW ref=0005631
I have XML tag that has the content which is HTML document. <xml-tag> <!--
I have some XML that is structured like this: <whatson> <productions> <production> <category>Film</category> </production>
I have an XML that goes like this: <?xml version=1.0 encoding=utf-8 ?> <colors> <color

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.