Solved

Attempting to extract ddata from 5-level deep XML document - specifically, attributes from two different levels through XSL

Posted on 2006-06-12
2
472 Views
Last Modified: 2013-11-19
Hi,

I am using the following XML sample data:

<Updates>
            <Update CreationDate="2006-06-02T20:47:13Z" DefaultLanguage="en" UpdateId="5e1f52f5-064a-4187-b3e2-58052c2334e6" RevisionNumber="100" RevisionId="304144" DeploymentAction="Evaluate" IsLeaf="true" IsSoftware="false" />
            <Update CreationDate="2006-06-02T20:47:04Z" DefaultLanguage="en" UpdateId="0f4d525a-35cd-44ed-9166-66a156b28384" RevisionNumber="100" RevisionId="304143" DeploymentAction="Evaluate" IsLeaf="true" IsSoftware="false" />
            <Update CreationDate="2006-06-02T20:46:58Z" DefaultLanguage="en" UpdateId="797160f7-23db-4715-843c-4c98c65bcee5" RevisionNumber="100" RevisionId="304142" DeploymentAction="Evaluate" IsLeaf="true" IsSoftware="false" />
            <Update CreationDate="2006-06-02T20:46:50Z" DefaultLanguage="en" UpdateId="669663e5-6d84-45b3-8f87-f2576c42abed" RevisionNumber="100" RevisionId="304141" DeploymentAction="Evaluate" IsLeaf="true" IsSoftware="false" />
            <Update CreationDate="2006-06-02T20:46:45Z" DefaultLanguage="en" UpdateId="9d8d6815-4bd8-435a-8e3c-c330e6558509" RevisionNumber="100" RevisionId="304140" DeploymentAction="Evaluate" IsSoftware="false" />
            <Update CreationDate="2006-06-02T20:46:39Z" DefaultLanguage="en" UpdateId="fb905d6a-41dd-42b7-b3ba-a5dfee2df916" RevisionNumber="100" RevisionId="304139" DeploymentAction="Evaluate" IsSoftware="false" />
            <Update CreationDate="2006-06-02T20:46:35Z" DefaultLanguage="en" UpdateId="56a1f6a9-4250-4cd5-8298-4f5107150bd0" RevisionNumber="100" RevisionId="304138" DeploymentAction="Evaluate" IsSoftware="false" />
            <Update CreationDate="2006-05-24T23:26:50Z" DefaultLanguage="en" UpdateId="d56652aa-8200-4942-9868-38c60dba6deb" RevisionNumber="101" RevisionId="301164" IsLeaf="true" DownloadPriority="Low" IsBundle="true">
                  <Categories>
                        <Category Type="Company" Id="56309036-4c77-4dd9-951a-99ee9c246a94" />
                        <Category Type="Product" Id="60916385-7546-4e9b-836e-79d65e517bab" />
                        <Category Type="ProductFamily" Id="0a4c6c73-8887-4d7f-9cbe-d08fa8fa9d1e" />
                        <Category Type="UpdateClassification" Id="68c5b0a3-d1a6-4553-ae49-01d3a7827828" />
                  </Categories>
                  <Prerequisites>
                        <UpdateId Id="68c5b0a3-d1a6-4553-ae49-01d3a7827828" />
                        <UpdateId Id="60916385-7546-4e9b-836e-79d65e517bab" />
                  </Prerequisites>
                  <Languages>
                        <Language Name="en" />
                        <Language Name="fr" />
                        <Language Name="de" />
                        <Language Name="it" />
                        <Language Name="ja" />
                        <Language Name="ko" />
                        <Language Name="zh-cn" />
                        <Language Name="es" />
                        <Language Name="zh-tw" />
                  </Languages>
            </Update>
            <Update CreationDate="2006-05-24T23:26:50Z" DefaultLanguage="en" UpdateId="43d2a0ce-9701-4bc1-898a-3fd4673fb520" RevisionNumber="101" RevisionId="301163" DeploymentAction="Bundle" IsLeaf="true">
                  <PayloadFiles>
                        <File Id="0Nz5rS/bjn/0RJBD95ogsmgyh5g=" />
                  </PayloadFiles>
                  <Prerequisites>
                        <UpdateId Id="93f895f7-fa38-4d08-8e73-ea0e3ca2d3b8" />
                        <UpdateId Id="aba2eeaa-11a4-4750-b0d7-1d22930d88cd" />
                        <UpdateId Id="60916385-7546-4e9b-836e-79d65e517bab" />
                  </Prerequisites>
                  <BundledBy>
                        <Revision Id="301164" />
                  </BundledBy>
                  <Languages>
                        <Language Name="fr" />
                  </Languages>
            </Update>
            <Update CreationDate="2006-05-24T23:26:50Z" DefaultLanguage="en" UpdateId="11cc0838-37b4-4a37-9980-848fc4f22506" RevisionNumber="101" RevisionId="301162" DeploymentAction="Bundle" IsLeaf="true">
                  <PayloadFiles>
                        <File Id="E8K/XoxAQJGxNo8IWS6un0JCeFI=" />
                  </PayloadFiles>
                  <Prerequisites>
                        <UpdateId Id="5fdb35d0-1a4d-4e1a-bcf5-ce1356d9828d" />
                        <UpdateId Id="aba2eeaa-11a4-4750-b0d7-1d22930d88cd" />
                        <UpdateId Id="60916385-7546-4e9b-836e-79d65e517bab" />
                  </Prerequisites>
                  <BundledBy>
                        <Revision Id="301164" />
                  </BundledBy>
                  <Languages>
                        <Language Name="ja" />
                  </Languages>
            </Update>


and the following XSL transform sheet

<?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" indent="yes"/>
      <xsl:template match="Updates">
            <xsl:apply-templates />
      </xsl:template>
      <xsl:template match="Update">
            <UpdateId>
                  <xsl:apply-templates select="@UpdateId" />
            </UpdateId>
      </xsl:template>
      <xsl:template match="File">
            <xsl:copy>
                  <xsl:apply-templates select="@Id" />
            </xsl:copy>
      </xsl:template>
</xsl:stylesheet>


To achieve the following data format:

<Updates>
      <Update UpdateId="43d2a0ce-9701-4bc1-898a-3fd4673fb520">
      <File Id="E8K/XoxAQJGxNo8IWS6un0JCeFI=">
</Updates>
<Updates>
      <Update UpdateId="43d2a0ce-9701-4bc1-898a-3fd4673fb520">
      <File Id="E8K/XoxAQJGxNo8IWS6un0JCeFI=">
</Updates>
<Updates>
      <Update UpdateId="43d2a0ce-9701-4bc1-898a-3fd4673fb520">
      <File Id="E8K/XoxAQJGxNo8IWS6un0JCeFI=">
</Updates>

Note: the target data sample is repeated solely for this example.

I am trying to extract these two pieces of information using XSL and I am getting "either or" - either the UpdateId or the FileId. I am planning to load the resultant XML  into a SQL database.

Any help on this topic would be much appreciated.

cheers,

g


0
Comment
Question by:gregorylambert
2 Comments
 

Author Comment

by:gregorylambert
ID: 16889221
Hi,

I have figured out the solution.

Here is the XSL code:

<?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" indent="yes"/>
      <xsl:template match="Updates">
            <Data>
                  <xsl:for-each select="Update">
                        <Payload>
                              <UpdateId>
                                    <xsl:apply-templates select="@UpdateId"/>
                              </UpdateId>
                              <xsl:apply-templates />
                        </Payload>
                  </xsl:for-each>
            </Data>
      </xsl:template>
      <xsl:template match="File">
            <FileLocation>
                  <xsl:value-of select="@Id" />
            </FileLocation>
      </xsl:template>
</xsl:stylesheet>
0
 

Accepted Solution

by:
EE_AutoDeleter earned 0 total points
ID: 17068400
gregorylambert,
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.

EE_AutoDeleter
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question