This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Flat file to hierarchy?


Wendell, 

Thank you!  Your key advice, along with the generate-id() example in Michael
Kay's book that it pointed me toward (p. 495, 2nd edition), was just what
was needed. 

And one more xslt newbie was no longer able to avoid keys...

For the record, here's what I came up with as a result (see yesterday's
message for sample data):


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:key name="Records-by-parent-A" match="RECORD[F1='A']"
use="generate-id(preceding-sibling::RECORD[F1='C' or F1='P'][1])"/>
	<xsl:key name="Records-by-parent-C" match="RECORD[F1='C']"
use="generate-id(preceding-sibling::RECORD[F1='P'][1])"/>
	<xsl:template match="RECORDS">
		<SUDOC-INDEX>
			<xsl:for-each select="RECORD[F1='P']">
				<AGENCY-GROUP>
					<AGENCY-GROUP-HEAD>
						<xsl:value-of select="F4"/>
					</AGENCY-GROUP-HEAD>
					<xsl:variable name="A-id"
select="generate-id()"/>
					<xsl:for-each
select="key('Records-by-parent-A', $A-id)">
						<AGENCY-RPT-NO-ENTRY>
							<AGENCY-RPT-NO>
	
<xsl:value-of select="F5"/>
							</AGENCY-RPT-NO>
							<ACCESSION-NO-GROUP>
	
<ISSUE-NUMBER>
	
<xsl:value-of select="F7"/>
	
</ISSUE-NUMBER>
	
<ACCESSION-NO>
	
<xsl:value-of select="F6"/>
	
</ACCESSION-NO>
	
</ACCESSION-NO-GROUP>
						</AGENCY-RPT-NO-ENTRY>
					</xsl:for-each>
					<xsl:variable name="C-id"
select="generate-id()"/>
					<xsl:for-each
select="key('Records-by-parent-C', $C-id)">
						<AGENCY-GROUP-LEVEL-TWO>
							<xsl:value-of
select="F4"/>
							<xsl:variable
name="A-id" select="generate-id()"/>
							<xsl:for-each
select="key('Records-by-parent-A', $A-id)">
	
<AGENCY-RPT-NO-ENTRY>
	
<AGENCY-RPT-NO>
	
<xsl:value-of select="F5"/>
	
</AGENCY-RPT-NO>
	
<ACCESSION-NO-GROUP>
	
<ISSUE-NUMBER>
	
<xsl:value-of select="F7"/>
	
</ISSUE-NUMBER>
	
<ACCESSION-NO>
	
<xsl:value-of select="F6"/>
	
</ACCESSION-NO>
	
</ACCESSION-NO-GROUP>
	
</AGENCY-RPT-NO-ENTRY>
							</xsl:for-each>
						</AGENCY-GROUP-LEVEL-TWO>
					</xsl:for-each>
				</AGENCY-GROUP>
			</xsl:for-each>
		</SUDOC-INDEX>
	</xsl:template>
</xsl:stylesheet>


Allison Denny
Data Analyst
4520 East-West Highway
Bethesda, MD  20814
Tel: 240.497.4015

LexisNexis
It's how you know 



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]