result-document and atomic values.

Here should go questions about transforming XML with XSLT and FOP.
magnet
Posts: 2
Joined: Thu Jul 23, 2009 11:05 pm

result-document and atomic values.

Post by magnet »

Hi

This is my dummy data...

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<Root>
<row>
<company>Tree House Int.</company>
<account_num>2823994756</account_num>
<representative>Bob Schafer</representative>
<type>supplier</type>
</row>
<row>
<company>Whatola</company>
<account_num>567123456</account_num>
<representative>Jane Adamms</representative>
<type>manufacturer</type>
</row>
<row>
<company>LKJ Industrial</company>
<account_num>298347987</account_num>
<representative>Tyler Warrent</representative>
<type>recycler</type>
</row>
<row>
<company>D+J Watson Ent.</company>
<account_num>456734</account_num>
<representative>Janet Lerpray</representative>
<type>supplier</type>
</row>
<row>
<company>Whatola</company>
<account_num>1111114</account_num>
<representative>Elouise Peabody</representative>
<type>manufacturer</type>
</row>
</Root>
This is my .xsl

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="distinct-values(//company)">
<xsl:variable name="cmpname" select="." />
<xsl:value-of select="$cmpname" />
<xsl:result-document href="{$cmpname}">

</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
My question:
I want to get the values of the <account_num> and <representative> nodes for each company, into the generated files. Using distinct-values, i can get the xsl to create a file for each company.. but if i try something like this..

Code: Select all

      <xsl:result-document href="{$cmpname}">
<xsl:value-of select="../representative"/>
</xsl:result-document>
I get the following error.
F [Saxon-B 9.0.0.6] Axis step child::element(account_num, xs:anyType) cannot be used here: the context item is an atomic value

Any ideas how i can get actual node information instead of atomic values in this context? (i am a noob so that may not sound right).
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: result-document and atomic values.

Post by george »

Something like below:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:variable name="document" select="."/>
<xsl:for-each select="distinct-values(//company)">
<xsl:variable name="cmpname" select="." />
<xsl:value-of select="$cmpname" />
<xsl:result-document href="{$cmpname}">
<xsl:value-of select="$document//representative[../company=$cmpname]" separator=","/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Regards,
George
George Cristian Bina
magnet
Posts: 2
Joined: Thu Jul 23, 2009 11:05 pm

Re: result-document and atomic values.

Post by magnet »

Awesome, Thanks!
Post Reply