[xsl] First Element Event

Subject: [xsl] First Element Event
From: "Pape, Nathan S." <Nathan.Pape@xxxxxxx>
Date: Wed, 7 Sep 2005 16:12:17 -0700
Basically my source document contains a group of two or more aliases, as
in the element named: <OTHER_NAME>
, and I just need to move them to the result tree under only one
element:
(<abcxyz:field name="T2_AKA" number="19">),
as shown below.
Consider the following input tree fragment:
<IND>
<ABC:NAME_LAST>REITER</ABC:NAME_LAST>
<ABC:NAME_FIRST>ED</ABC:NAME_FIRST>
<ABC:NAME_MIDDLE>AWARECO</ABC:NAME_MIDDLE>
<OTHER_NAME>
<XYZ:Name>DE STEFAMO, ALEX</XYZ:Name>
</OTHER_NAME>
<OTHER_NAME>
<XYZ:Name>JURSA, WILLIAM, JR</XYZ:Name>
</OTHER_NAME>
</IND>
I want the result tree (fragment) to look like this:
<abcxyz:field name="T2_NAM" number="18">
<abcxyz:subfield>
<abcxyz:item>REITER,ED AWARECO</abcxyz:item>
</abcxyz:subfield>
</abcxyz:field>
<abcxyz:field name="T2_AKA" number="19">
<abcxyz:subfield>
<abcxyz:item>DE STEFAMO, ALEX</abcxyz:item>
</abcxyz:subfield>
<abcxyz:subfield>
<abcxyz:item>JURSA, WILLIAM, JR</abcxyz:item>
</abcxyz:subfield>
</abcxyz:field>
(Note the above list of aliases -- contained in one header block.)
(Does this imply using 'group' based techniques?)
My XSLT code looks like this:
(Top level template)
<xsl:template match="/">
<xsl:element name="abcxyz:transaction"
<xsl:element name="abcxyz:record">
<xsl:attribute name="type"><xsl:value-of select="2"/></xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:element>
</xsl:template>
(Lower level template to process each record contained in the
transaction file.)
<xsl:template name="process_record" match="*">
<xsl:for-each select=".">
<xsl:variable name="IND_NAME">
<xsl:value-of select="name()"/>
</xsl:variable>
<xsl:when test="$IND_NAME='OTHER_NAME'">
(This is where I just want this to put out only one 'enclosing' element,
(just once), and I've tried lots of ways but can't 'say it' in
XSLT-speak.)
<xsl:if test="( IND[position( )= 1] ) " >
<xsl:element name="abcxyz:field">
<xsl:attribute name="name"><xsl:value-of
select="'T2_AKA'"/></xsl:attribute>
<xsl:attribute name="number"><xsl:value-of select="19"/></xsl:attribute>

</xsl:element>
</xsl:if>
(Then this is the part that I want to put out the 'list' of the aliases
(corresponding to <OTHER_NAME>), in the input)
<xsl:if test="count(child::*) > 1 " >
<xsl:element name="abcxyz:subfield">
<xsl:element name="abcxyz:item">
<xsl:value-of select="./XYZ:Name"/>
</xsl:element>
</xsl:element>
</xsl:if>
</xsl:when>
I've also tried combining these two elements, and that isn't right
either.
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Instead, I get either a repeat of the header field (abcxyz:field
name="T2_AKA" number="19">), or no header field, depending on my code; I
can't get just one instance of the header, (as shown in the desired
output); below --- this is some of the actual (erroneous) fragment:
<abcxyz:field name="T2_AKA" number="19" />
<abcxyz:subfield>
<abcxyz:item>DE STEFAMO, ALEX</abcxyz:item>
</abcxyz:subfield>
<abcxyz:field name="T2_AKA" number="19" />
<abcxyz:subfield>
<abcxyz:item>JURSA, WILLIAM, JR</abcxyz:item>
</abcxyz:subfield>
(Note: it's not even ending the </abcxyz:field> tags!?)
Any Ideas?

Current Thread