Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Normalizing XML data
Message
 
To
06/08/2003 12:44:04
Keith Payne
Technical Marketing Solutions
Florida, United States
General information
Forum:
ASP.NET
Category:
XML
Miscellaneous
Thread ID:
00817166
Message ID:
00817411
Views:
15
This message has been marked as the solution to the initial question of the thread.
This should get you started:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<Data>
	<Lead>
		<xsl:apply-templates select="Data/Lead[not(DefendantNumber = preceding-sibling::Lead/DefendantNumber)]" mode="Defendant"/>
	</Lead>
</Data>
</xsl:template>


<xsl:template match="Lead" mode="Defendant">
	<DefendantNumber><xsl:value-of select="DefendantNumber"/></DefendantNumber>
	<FirstName><xsl:value-of select="FirstName"/></FirstName>
		<xsl:apply-templates select="../Lead[DefendantNumber = ./DefendantNumber]" mode="Count"/>
</xsl:template>

<xsl:template match="Lead" mode="Count">
	<Count>
		<CountSequenceNo><xsl:apply-templates select="CountSequenceNo"/></CountSequenceNo>
		<Offense><xsl:apply-templates select="Offense"/></Offense>
	</Count>
</xsl:template>
</xsl:stylesheet>
>The result I'm looking for is:
>
><Data>
>	<Lead>
>		<DefendantNumber>09999999CF10A</DefendantNumber>
>		<FirstName>GEORGE</FirstName>
>		<Count>
>			<CountSequenceNo>001</CountSequenceNo>
>			<Offense>SELL/MAN/DEL POSS/W/INT C</Offense>
>		</Count>
>		<Count>
>			<CountSequenceNo>002</CountSequenceNo>
>			<Offense>POSSESSION OF COCAINE</Offense>
>		</Count>
>	</Lead>
></Data>
>
>
>I suppose it could be called "un-flattening" ;)
>
>>Normalization is not really a term that applies to XML data. What kind of output are you looking for?
>>
>>>I have the following data in an XML document and I'm looking to normalize the structure using XSLT:
>>>
>>><Data>
>>>  <Lead>
>>>    <DefendantNumber>09999999CF10A</DefendantNumber>
>>>    <FirstName>GEORGE</FirstName>
>>>    <CountSequenceNo>001</CountSequenceNo>
>>>    <Offense>SELL/MAN/DEL POSS/W/INT C</Offense>
>>>  </Lead>
>>>  <Lead>
>>>    <DefendantNumber>09999999CF10A</DefendantNumber>
>>>    <FirstName>GEORGE</FirstName>
>>>    <CountSequenceNo>002</CountSequenceNo>
>>>    <Offense>POSSESSION OF COCAINE</Offense>
>>>  </Lead>
>>></Data>
>>>
>>>
>>>This is my first foray into XSLT and the only samples I could find dealt with data stored as attributes. Does anyone have a link for a sample that deals specifically with normalizing the structure where the data is InnerText instead of an attribute? - A big plus would be a sample that does not involve HTML formatting.
>>>
>>>Or even better yet, could anyone whip up a quick XSL template that I could use to get started?
>>>
>>>Infinite thanks in advance,
>>>
>>>Keith
jMM
Previous
Reply
Map
View

Click here to load this message in the networking platform