Monday, 7 July 2014

How to create contents nodes out of an empty tokenized string in XSLT?



My application isn't creating content nodes for empty tokenized strings, so I'm wondering if it's the app or something in xslt that I'm messing up.


I have a string in a table row like:


|0001|United Health Foundation|10 Circle LN||New York|NY|


and like this


|0002|Red Cross|20 Bender LN|Suite 20|New York|NY|


So I'm tokenizing on the '|'



<xsl:template match="/">

<xsl:apply-templates select="//tr" />

</xsl:template>

<xsl:template match="tr">

<xsl:for-each select=".">
<xsl:variable name="part" select="str:tokenize(.,'|')" />
<document>
<content name="id">
<xsl:value-of select="$part[1]" />
</content>
<content name="bizName">
<xsl:value-of select="$part[2]" />
</content>
<content name="street1">
<xsl:value-of select="$part[3]" />
</content>
<content name="street2">
<xsl:value-of select="$part[4]" />
</content>
<content name="city">
<xsl:value-of select="$part[5]" />
</content>
<content name="state">
<xsl:value-of select="$part[6]" />
</content>
</document>
</xsl:for-each>
</xsl:template>


The problem that I have is the first row has an empty string value for the 'street2' node (||). So my application is pushing everything one position left and street2 has the city value, city value has the state value and so on.


Can someone recommend a way to fix this or is this most likely something in my application?


Thanks for any help


No comments:

Post a Comment