サンプル XSLT
必要な XSLT ファイルを生成するには、サンプル XSLT を使用します。
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
>
<xsl:variable name="styleTableBorder">border: 2px solid black;border-collapse:collapse;padding-left: 5px;</xsl:variable>
<xsl:variable name="style_td">width: 25%; padding-left: 5px;</xsl:variable>
<xsl:variable name="styleSubTotal1">border: 1px solid black;border-collapse:collapse;padding: 10px;vertical-align:top; </xsl:variable>
<xsl:variable name="styleSummaryPart2">padding: 10px;text-align:right;</xsl:variable>
<xsl:variable name="styleLightSkyBlueColor">background-color: #ebf9fc;</xsl:variable>
<xsl:variable name="styleLightYellowColor">background-color: #e7e6d2;</xsl:variable>
<!--Entry point-->
<xsl:template match="/">
<xsl:apply-templates select="Documents/InvoiceData"/>
</xsl:template>
<xsl:template name="renderFields">
<xsl:param name="nodes"></xsl:param>
<xsl:param name="startindex"></xsl:param>
<xsl:param name="columncount"></xsl:param>
<xsl:variable name="count" select="count($nodes)" ></xsl:variable>
<xsl:variable name="endindex" select="$startindex + $columncount - 1"></xsl:variable>
<xsl:if test="$count >= $startindex ">
<tr xmlns="http://www.w3.org/1999/xhtml">
<!-- out of the node list, get only the nodes for which we want to generate the td tag. -->
<xsl:for-each select="$nodes[position() >= $startindex and not (position() > $endindex)]">
<!-- output is the value of the node-->
<td style="width:25%;padding-left: 5px; {$styleLightYellowColor};">
<xsl:value-of select="./@DisplayName"/>
</td>
<td style="width:25%;text-align:left;">
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</tr>
<!-- call this template recursively in order to loop through the next set of nodes -->
<xsl:call-template name="renderFields">
<xsl:with-param name="nodes" select="$nodes"></xsl:with-param>
<!-- make the startindex = endindex + 1 to get the next set of nodes -->
<xsl:with-param name="startindex" select="$endindex+1"></xsl:with-param>
<!-- keep the column count as it is -->
<xsl:with-param name="columncount" select="$columncount"></xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="Documents/InvoiceData">
<html>
<body style="width:98%">
<!--Header Part-->
<table style="height: 41px; width:100%;background-color:#0000fe;color:white;font-weight:bold">
<tbody>
<tr style="font-size:30px" >
<td style="width: 50%; padding-left: 12px; ">
<xsl:value-of select="Header/@Title"></xsl:value-of>
</td>
<td style="width: 50%; text-align: right; padding-right: 12px;">
<xsl:value-of select="Header/@InvoiceType"></xsl:value-of>
</td>
</tr>
</tbody>
</table>
<br></br>
<!--Invoice Id Fields-->
<table style="width:100%;{$styleTableBorder};border: 0px ">
<tbody>
<tr style="">
<td style="width:50%"></td>
<td style="{$style_td}">
<xsl:value-of select="IdFields/InvoiceDate/@DisplayName"></xsl:value-of>
</td>
<td style="{$style_td}">
<xsl:value-of select="IdFields/InvoiceNumber/@DisplayName"></xsl:value-of>
</td>
</tr>
<tr style="">
<td></td>
<td style="{$styleTableBorder}">
<xsl:value-of select="IdFields/InvoiceDate"></xsl:value-of>
</td>
<td style="{$styleTableBorder}">
<xsl:value-of select="IdFields/InvoiceNumber"></xsl:value-of>
</td>
</tr>
</tbody>
</table>
<br></br>
<!--Buyer & Seller Data-->
<table style="width:100%;">
<tbody>
<tr>
<td style="width:50%">
<table style="width:100%;">
<tr style=" ">
<td style=" width:50%">
<u>
<xsl:value-of select="Buyer/@Title"></xsl:value-of>
</u>
</td>
<td style="width:50%"></td>
</tr>
<tr style="height:25px"></tr>
<xsl:for-each select="Buyer/*">
<tr>
<td style="padding-left: 5px; {$styleLightYellowColor};">
<xsl:value-of select="current()/@DisplayName"/>
</td>
<td>
<xsl:value-of select="current()"/>
</td>
</tr>
</xsl:for-each>
</table>
</td>
<td style="width:50%">
<table style="width:100%;">
<tr style="">
<u>
<xsl:value-of select="Supplier/@Title"></xsl:value-of>
</u>
<td style="width:50%"></td>
</tr>
<tr style="height:25px"></tr>
<xsl:for-each select="Supplier/*">
<tr>
<td style="padding-left: 5px; {$styleLightYellowColor}">
<xsl:value-of select="current()/@DisplayName"/>
</td>
<td>
<xsl:value-of select="current()"/>
</td>
</tr>
</xsl:for-each>
</table>
</td>
</tr>
</tbody>
</table>
<br></br>
<hr style="height:2px;border:none;color:black;background-color:black;" />
<br></br>
<table style="width:100%;">
<!-- call rendertr template with paramter-->
<xsl:call-template name="renderFields">
<!-- select all "InvoiceFields" nodes and pass it as a parameter to the xslt template-->
<xsl:with-param name="nodes" select="InvoiceFields/*"></xsl:with-param>
<xsl:with-param name="startindex">1</xsl:with-param>
<!-- change the column count as per your need -->
<xsl:with-param name="columncount">2</xsl:with-param>
</xsl:call-template>
</table>
<br></br>
<!--Line Items Data-->
<xsl:value-of select="LineItems/@Title"></xsl:value-of>
<br></br>
<table style="width:100%;padding-top:10px;{$styleSubTotal1}">
<thead>
<tr>
<xsl:for-each select="LineItems/LineItem[1]/*">
<th style="text-align:center;{$styleSubTotal1}{styleLightSkyBlueColor}">
<xsl:value-of select="current()/@DisplayName"/>
</th>
</xsl:for-each>
</tr>
</thead>
<xsl:for-each select="LineItems/*">
<tr>
<xsl:for-each select="current()/*">
<xsl:variable name="styleTextAlign" select="concat('text-align:',current()/@Alignment)"/>
<td style="{$styleSubTotal1};{$styleTextAlign}">
<xsl:value-of select="current()"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
<br />
<!--Attachments Data-->
<div style="padding-bottom:10px;">
<b>
<xsl:value-of select="Attachments/@Title"></xsl:value-of>
</b>
</div>
<table style="width:100%;{$styleSubTotal1};padding-top:10px;">
<thead>
<tr>
<xsl:for-each select="Attachments/Attachment[1]/*">
<th style="text-align:center;{$styleSubTotal1}{$styleLightSkyBlueColor}">
<xsl:value-of select="current()/@DisplayName"/>
</th>
</xsl:for-each>
</tr>
</thead>
<xsl:for-each select="Attachments/*">
<tr>
<xsl:for-each select="current()/*">
<td style="{$styleSubTotal1}">
<xsl:value-of select="current()"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
<br></br>
<!--Notes-->
<table style="width: 100%; border: 0px solid black;border-collapse:collapse;padding:10px;">
<tr>
<td style="border: 1px solid black; border:none;border-bottom:solid;">
<b>
<xsl:value-of select="Notes/@Title"></xsl:value-of>
</b>
</td>
</tr>
<tr>
<td style="border: 0px solid black; border-collapse: collapse;">
<xsl:value-of select="Notes/InvoiceNote"></xsl:value-of>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>