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
466 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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now