[xquery-talk] XML to TEXT OUTPUT with xQUERY

G. Ken Holman gkholman at CraneSoftwrights.com
Fri Dec 3 11:13:26 PST 2010


At 2010-12-03 19:40 +0100, Julio de la Vega wrote:
>I send an example of the input file. For every metadata node I need 
>to generate a line of information in a flat file. I have had 
>different results using the same xquery with different xquery engines.
>
>Michale, for example with saxonHE I do not get any output if I use 
>!method=text.

Below is an example of your data and a solution running under Saxon.

I hope this helps.

. . . . . . . . Ken


T:\ftemp>type julio.xml
<root>

<MetaData>

    <Partition>

       <!-- Partition Level Attributes -->

       <Attr name="PartitionNO" value="1" />

       <Attr name="TotalPagesInPartition" value="15346" />

       <Attr name="TotalRectoPagesInPartition" value="7673" />

       <Attr name="TotalVersoPagesInPartition" value="7673" />

       <Attr name="TotalBlankPagesInsertedInPartition" value="1487" />

       <Attr name="TotalSheetsInPartition" value="7673" />

       <Attr name="CurrentPackageInPartition" value="5705" />

       <Attr name="partitionMetaDataFile" 
value="D:\GBPXI\OUT\Print\Extractos\00229-X-00000005_20101108082610_F1_XIGRUPO_101104.afp.xml" 
/>

    </Partition>

    <!-- Stream Level Attributes -->

    <Attr name="TotalPagesInStream" value="15346" />

    <Attr name="TotalSheetsInStream" value="7673" />

    <Attr name="TotalBlankPagesInsertedInStream" value="1487" />

    <Attr name="TotalPartitionsInStream" value="1" />

</MetaData>

<MetaData >

    <Partition>

       <!-- Partition Level Attributes -->

       <Attr name="PartitionNO" value="1" />

       <Attr name="TotalPagesInPartition" value="25567" />

       <Attr name="TotalRectoPagesInPartition" value="3444" />

       <Attr name="TotalVersoPagesInPartition" value="3444" />

       <Attr name="TotalBlankPagesInsertedInPartition" value="1487" />

       <Attr name="TotalSheetsInPartition" value="7673" />

       <Attr name="CurrentPackageInPartition" value="5705" />

       <Attr name="partitionMetaDataFile" 
value="D:\GBPXI\OUT\Print\Extractos\00229-Y-00000005_20101108082610_F1_XIGRUPO_101104.afp.xml" 
/>

    </Partition>

    <!-- Stream Level Attributes -->

    <Attr name="TotalPagesInStream" value="15346" />

    <Attr name="TotalSheetsInStream" value="7673" />

    <Attr name="TotalBlankPagesInsertedInStream" value="1487" />

    <Attr name="TotalPartitionsInStream" value="1" />

</MetaData>

</root>
T:\ftemp>call xquery julio.xq
D:\GBPXI\OUT\Print\Extractos\00229-X-00000005_20101108082610_F1_XIGRUPO_101104.afp.xml
D:\GBPXI\OUT\Print\Extractos\00229-Y-00000005_20101108082610_F1_XIGRUPO_101104.afp.xml

T:\ftemp>type julio.xq
declare namespace saxon="http://saxon.sf.net/";
declare option saxon:output "method=text";

let $root:=doc("julio.xml")
return string-join( ( $root/*/*/*/Attr[@name="partitionMetaDataFile"]/@value,
                       '' ),
                     '&#xa;' )

T:\ftemp>rem Done!



--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
G. Ken Holman                 mailto:gkholman at CraneSoftwrights.com
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal



More information about the talk mailing list