gregorylambert
asked on
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-02T2 0:47:13Z" DefaultLanguage="en" UpdateId="5e1f52f5-064a-41 87-b3e2-58 052c2334e6 " RevisionNumber="100" RevisionId="304144" DeploymentAction="Evaluate " IsLeaf="true" IsSoftware="false" />
<Update CreationDate="2006-06-02T2 0:47:04Z" DefaultLanguage="en" UpdateId="0f4d525a-35cd-44 ed-9166-66 a156b28384 " RevisionNumber="100" RevisionId="304143" DeploymentAction="Evaluate " IsLeaf="true" IsSoftware="false" />
<Update CreationDate="2006-06-02T2 0:46:58Z" DefaultLanguage="en" UpdateId="797160f7-23db-47 15-843c-4c 98c65bcee5 " RevisionNumber="100" RevisionId="304142" DeploymentAction="Evaluate " IsLeaf="true" IsSoftware="false" />
<Update CreationDate="2006-06-02T2 0:46:50Z" DefaultLanguage="en" UpdateId="669663e5-6d84-45 b3-8f87-f2 576c42abed " RevisionNumber="100" RevisionId="304141" DeploymentAction="Evaluate " IsLeaf="true" IsSoftware="false" />
<Update CreationDate="2006-06-02T2 0:46:45Z" DefaultLanguage="en" UpdateId="9d8d6815-4bd8-43 5a-8e3c-c3 30e6558509 " RevisionNumber="100" RevisionId="304140" DeploymentAction="Evaluate " IsSoftware="false" />
<Update CreationDate="2006-06-02T2 0:46:39Z" DefaultLanguage="en" UpdateId="fb905d6a-41dd-42 b7-b3ba-a5 dfee2df916 " RevisionNumber="100" RevisionId="304139" DeploymentAction="Evaluate " IsSoftware="false" />
<Update CreationDate="2006-06-02T2 0:46:35Z" DefaultLanguage="en" UpdateId="56a1f6a9-4250-4c d5-8298-4f 5107150bd0 " RevisionNumber="100" RevisionId="304138" DeploymentAction="Evaluate " IsSoftware="false" />
<Update CreationDate="2006-05-24T2 3:26:50Z" DefaultLanguage="en" UpdateId="d56652aa-8200-49 42-9868-38 c60dba6deb " RevisionNumber="101" RevisionId="301164" IsLeaf="true" DownloadPriority="Low" IsBundle="true">
<Categories>
<Category Type="Company" Id="56309036-4c77-4dd9-951 a-99ee9c24 6a94" />
<Category Type="Product" Id="60916385-7546-4e9b-836 e-79d65e51 7bab" />
<Category Type="ProductFamily" Id="0a4c6c73-8887-4d7f-9cb e-d08fa8fa 9d1e" />
<Category Type="UpdateClassification " Id="68c5b0a3-d1a6-4553-ae4 9-01d3a782 7828" />
</Categories>
<Prerequisites>
<UpdateId Id="68c5b0a3-d1a6-4553-ae4 9-01d3a782 7828" />
<UpdateId Id="60916385-7546-4e9b-836 e-79d65e51 7bab" />
</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-24T2 3:26:50Z" DefaultLanguage="en" UpdateId="43d2a0ce-9701-4b c1-898a-3f d4673fb520 " RevisionNumber="101" RevisionId="301163" DeploymentAction="Bundle" IsLeaf="true">
<PayloadFiles>
<File Id="0Nz5rS/bjn/0RJBD95ogsm gyh5g=" />
</PayloadFiles>
<Prerequisites>
<UpdateId Id="93f895f7-fa38-4d08-8e7 3-ea0e3ca2 d3b8" />
<UpdateId Id="aba2eeaa-11a4-4750-b0d 7-1d22930d 88cd" />
<UpdateId Id="60916385-7546-4e9b-836 e-79d65e51 7bab" />
</Prerequisites>
<BundledBy>
<Revision Id="301164" />
</BundledBy>
<Languages>
<Language Name="fr" />
</Languages>
</Update>
<Update CreationDate="2006-05-24T2 3:26:50Z" DefaultLanguage="en" UpdateId="11cc0838-37b4-4a 37-9980-84 8fc4f22506 " RevisionNumber="101" RevisionId="301162" DeploymentAction="Bundle" IsLeaf="true">
<PayloadFiles>
<File Id="E8K/XoxAQJGxNo8IWS6un0 JCeFI=" />
</PayloadFiles>
<Prerequisites>
<UpdateId Id="5fdb35d0-1a4d-4e1a-bcf 5-ce1356d9 828d" />
<UpdateId Id="aba2eeaa-11a4-4750-b0d 7-1d22930d 88cd" />
<UpdateId Id="60916385-7546-4e9b-836 e-79d65e51 7bab" />
</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-4b c1-898a-3f d4673fb520 ">
<File Id="E8K/XoxAQJGxNo8IWS6un0 JCeFI=">
</Updates>
<Updates>
<Update UpdateId="43d2a0ce-9701-4b c1-898a-3f d4673fb520 ">
<File Id="E8K/XoxAQJGxNo8IWS6un0 JCeFI=">
</Updates>
<Updates>
<Update UpdateId="43d2a0ce-9701-4b c1-898a-3f d4673fb520 ">
<File Id="E8K/XoxAQJGxNo8IWS6un0 JCeFI=">
</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
I am using the following XML sample data:
<Updates>
<Update CreationDate="2006-06-02T2
<Update CreationDate="2006-06-02T2
<Update CreationDate="2006-06-02T2
<Update CreationDate="2006-06-02T2
<Update CreationDate="2006-06-02T2
<Update CreationDate="2006-06-02T2
<Update CreationDate="2006-06-02T2
<Update CreationDate="2006-05-24T2
<Categories>
<Category Type="Company" Id="56309036-4c77-4dd9-951
<Category Type="Product" Id="60916385-7546-4e9b-836
<Category Type="ProductFamily" Id="0a4c6c73-8887-4d7f-9cb
<Category Type="UpdateClassification
</Categories>
<Prerequisites>
<UpdateId Id="68c5b0a3-d1a6-4553-ae4
<UpdateId Id="60916385-7546-4e9b-836
</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-24T2
<PayloadFiles>
<File Id="0Nz5rS/bjn/0RJBD95ogsm
</PayloadFiles>
<Prerequisites>
<UpdateId Id="93f895f7-fa38-4d08-8e7
<UpdateId Id="aba2eeaa-11a4-4750-b0d
<UpdateId Id="60916385-7546-4e9b-836
</Prerequisites>
<BundledBy>
<Revision Id="301164" />
</BundledBy>
<Languages>
<Language Name="fr" />
</Languages>
</Update>
<Update CreationDate="2006-05-24T2
<PayloadFiles>
<File Id="E8K/XoxAQJGxNo8IWS6un0
</PayloadFiles>
<Prerequisites>
<UpdateId Id="5fdb35d0-1a4d-4e1a-bcf
<UpdateId Id="aba2eeaa-11a4-4750-b0d
<UpdateId Id="60916385-7546-4e9b-836
</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-4b
<File Id="E8K/XoxAQJGxNo8IWS6un0
</Updates>
<Updates>
<Update UpdateId="43d2a0ce-9701-4b
<File Id="E8K/XoxAQJGxNo8IWS6un0
</Updates>
<Updates>
<Update UpdateId="43d2a0ce-9701-4b
<File Id="E8K/XoxAQJGxNo8IWS6un0
</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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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>