Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 506
  • Last Modified:

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

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
gregorylambert
Asked:
gregorylambert
1 Solution
 
gregorylambertAuthor Commented:
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
 
EE_AutoDeleterCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now