Here is an XSLT 1.0 stylesheet that outputs the names of child elements in a header line, then the values in following lines:
Code:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:param name="nl" select="'
'"/>
<xsl:param name="sep" select="'|'"/>
<xsl:template match="/">
<xsl:apply-templates select="service/serviceBody/serviceResponse/paymentHistoryList/paymentHistoryInfo[1]/*" mode="header"/>
<xsl:apply-templates select="service/serviceBody/serviceResponse/paymentHistoryList/paymentHistoryInfo"/>
</xsl:template>
<xsl:template match="paymentHistoryInfo/*" mode="header">
<xsl:value-of select="local-name()"/>
<xsl:choose>
<xsl:when test="position() != last()">
<xsl:value-of select="$sep"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$nl"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="paymentHistoryInfo">
<xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="paymentHistoryInfo/*" >
<xsl:value-of select="."/>
<xsl:choose>
<xsl:when test="position() != last()">
<xsl:value-of select="$sep"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$nl"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
When applied to the input document
Code:
<?xml version="1.0" encoding="utf-8" ?>
<service>
<serviceHeader>
<billingSys>VISION_EAST</billingSys>
<clientId>VZW-FIN</clientId>
<userId>00000003</userId>
<password>01VISION</password>
<serviceName>PaymentHistoryInquiry</serviceName>
<statusCode>00</statusCode>
<errorCode>00</errorCode>
<errorMsg/>
<cicsErrorCode>00</cicsErrorCode>
<serverName>vmwdev2</serverName>
<correlationId>c48e6a2ad3c47cc5:-2cb74c38:11f810f0494:-7a85:vmwdev2:DVSCOMMON</correlationId>
</serviceHeader>
<serviceBody>
<serviceRequest>
<accountNo>15241-1</accountNo>
</serviceRequest>
<serviceResponse>
<paymentHistoryRowCount>100</paymentHistoryRowCount>
<paymentHistoryList>
<paymentHistoryInfo>
<invoiceDate>200812</invoiceDate>
<invoiceNumber>1493001562</invoiceNumber>
<previousBalance>84.91</previousBalance>
<paymentsRecieved>84.91</paymentsRecieved>
<balanceForward>0.0</balanceForward>
<currentCharges>83.96</currentCharges>
<totalBalance>83.96</totalBalance>
</paymentHistoryInfo>
<paymentHistoryInfo>
<invoiceDate>200811</invoiceDate>
<invoiceNumber>1482401248</invoiceNumber>
<previousBalance>173.66</previousBalance>
<paymentsRecieved>173.66</paymentsRecieved>
<balanceForward>0.0</balanceForward>
<currentCharges>84.91</currentCharges>
<totalBalance>84.91</totalBalance>
</paymentHistoryInfo>
</paymentHistoryList>
</serviceResponse>
</serviceBody>
</service>
the output is as follows:
Code:
invoiceDate|invoiceNumber|previousBalance|paymentsRecieved|balanceForward|currentCharges|totalBalance
200812|1493001562|84.91|84.91|0.0|83.96|83.96
200811|1482401248|173.66|173.66|0.0|84.91|84.91