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
479 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

707 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