java - Need custom order in flat file from XML using XSLT -


i want create flat file xml using xslt output in order shown:

nm1*cc*1*smith*john****34*999999999~
n3*100 main street~

from xml:

<claim>  <claimant     lastname="smith"     firstname="john"     middlename=""     suffixname=""     indentificationcodequalifier="34"     identificationcode="999999999">     <claimantstreetlocation         primary="100 main street"         secondary=""/>  </claimant> </claim> 

with xslt created output in reversed desired order shown below due nature of how xslt works traverses input tree i'm assuming:

n3*100 main street~
nm1*cc*1*smith*john****34*999999999~

what need change/add order looking xslt i've written shown: `

<xsl:template match="claim/claimant">     <xsl:apply-templates />     <xsl:text>nm1*cc*1*</xsl:text>     <xsl:value-of select="@lastname" />     <xsl:text>*</xsl:text>     <xsl:value-of select="@firstname" />     <xsl:text>*</xsl:text>     <xsl:value-of select="@middlename" />     <xsl:text>*</xsl:text>     <xsl:text>*</xsl:text>     <xsl:value-of select="@suffixname" />     <xsl:text>*</xsl:text>     <xsl:value-of select="@indentificationcodequalifier" />     <xsl:text>*</xsl:text>     <xsl:value-of select="@identificationcode" />     <xsl:text>~</xsl:text>     <xsl:text>     </xsl:text> </xsl:template>  <xsl:template match="claim/claimant/claimantstreetlocation">     <xsl:apply-templates />     <xsl:text>n3*</xsl:text>     <xsl:value-of select="@primary" />     <xsl:text>~</xsl:text>     <xsl:text>     </xsl:text> </xsl:template>` 

is there way without combining 2 tags one?

any feedback appreciated.

i don't know if matters, i'm using xalan-java process xslt in code.

if want process parent before children, should move apply-templates end of parent template:

<xsl:template match="claim/claimant">     <xsl:text>nm1*cc*1*</xsl:text>     <xsl:value-of select="@lastname" />     <xsl:text>*</xsl:text>     <xsl:value-of select="@firstname" />     <xsl:text>*</xsl:text>     <xsl:value-of select="@middlename" />     <xsl:text>*</xsl:text>     <xsl:text>*</xsl:text>     <xsl:value-of select="@suffixname" />     <xsl:text>*</xsl:text>     <xsl:value-of select="@indentificationcodequalifier" />     <xsl:text>*</xsl:text>     <xsl:value-of select="@identificationcode" />     <xsl:text>~</xsl:text>     <xsl:text>     </xsl:text>     <xsl:apply-templates /> </xsl:template>  <xsl:template match="claimantstreetlocation">     <xsl:apply-templates />     <xsl:text>n3*</xsl:text>     <xsl:value-of select="@primary" />     <xsl:text>~</xsl:text>     <xsl:text>     </xsl:text> </xsl:template>` 

update: what's happening here is:

  1. the first element processed claim, there no templates matching it, default template applies, process templates children nodes.

  2. there, first child claimant, , have template matches it, applied.

  3. next, template processed in order. critical point apply-templates omits attributes in default select (see what default select of xslt apply-templates?), matched node there claimantstreetlocation element.

  4. given have template matches claimantstreetlocation, applied. so, if want process first attributes, should delay apply-templates until selected, in case, manually.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -