Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Simple XSLT Assistance

Very new to XSLT looking for some assistance

10:09 pm on Jan 18, 2012 (gmt 0)

New User

5+ Year Member

joined:Jan 18, 2012
votes: 0

I've recently been assigned the task of converting some of our standard XML output to custom formats and I would love some assistance if anyone can provide it!

I have two differen output options I can work from:

<?xml version="1.0" encoding="UTF-8"?>
-<batch BatchName="20120118.132647">
-<document Doc_path="" Date_created="" Date_converted="" Batch_id="" Exception_reason="" Exception="" Remittance_adv="" Invoice_date="" Invoice_amount="" Invoice_num="" Property_code="" Vendor_code="" Doc_ID="">
-<files><file path="D:\Migration\00000001.tif"/></files></document></batch>


<?xml version="1.0" encoding="UTF-8"?>
-<Batch BatchName="20120118.132405" BatchID="107">
-<Document DocumentType="XSLT Sample Migration">
<Field FieldName="Doc_ID"/>
<Field FieldName="Vendor_code"/>
<Field FieldName="Property_code"/>
<Field FieldName="Invoice_num"/>
<Field FieldName="Invoice_amount"/>
<Field FieldName="Invoice_date"/>
<Field FieldName="Remittance_adv"/>
<Field FieldName="Exception"/>
<Field FieldName="Exception_reason"/>
<Field FieldName="Batch_id"/>
<Field FieldName="Date_converted"/>
<Field FieldName="Date_created"/><Field FieldName="Doc_path"/>

The first output I'm attempting to replicate is:

<?xml version="1.0" standalone="yes"?>
<property_code>PNFProperty Not Found</property_code>
<invoice_num />
<exception_reason>NO NSX#</exception_reason>
<doc_path>\\qaweb\Kofax Data\CLIENT\Images\00146B85.pdf</doc_path>

I've managed to generate an XSLT that produces the same exact output as the input, however as soon as I try to start modifying the output things break in a bad way.
2:05 am on Jan 19, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 31, 2005
votes: 0

Maybe this will get you started. This is for the second example.

<?xml version="1.0" encoding="utf-16" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
<xsl:template match="/">
<xsl:apply-templates select="/Batch" />
<xsl:template match="/Batch">
<xsl:for-each select="Document/Fields/Field">
<xsl:if test="@FieldName = 'Doc_ID'">
<xsl:value-of select="./text()" />
<xsl:value-of select="@BatchID" />
6:07 am on Jan 19, 2012 (gmt 0)

New User

5+ Year Member

joined:Jan 18, 2012
votes: 0

Thanks for the reply. I will give this a try and see how far I can get!