xslt - XML table to LaTeX -


suppose have xml table of form

<table>   <tr>     <td>first name:</td>     <td>bill gates</td>   </tr>   <tr>     <td rowspan="2">telephone:</td>     <td>555 77 854</td>   </tr>   <tr>     <td>555 77 855</td>   </tr> </table> 

that wish convert latex using xslt (i stole example elsewhere). result want is

\documentclass{memoir} \usepackage{multirow} \begin{document} \begin{tabular}{*{10}{c}}  first name & bill gates &\\  \multirow{2}{*}{telephone:}    & 555 77 854 &\\    & 555 77 855 & \end{tabular} \end{document} 

for part, there fair one-to-one-correspondence between 2 table formats. works quite part:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" omit-xml-declaration="yes" encoding="utf-8"/>  <xsl:template match="/">  \documentclass{memoir} \usepackage{multirow} \begin{document}  <xsl:apply-templates/>  \end{document}  </xsl:template>  <xsl:template match="table"> \begin{tabular}{*{10}{c}} <xsl:apply-templates/> \end{tabular} </xsl:template>  <xsl:template match="tr"> <xsl:apply-templates />\\ </xsl:template>  <xsl:template match="td[not(@rowspan) , not(@colspan)]"> <xsl:apply-templates/> &amp; </xsl:template>  <xsl:template match="td[not(@colspoan)]"> \multirow{<xsl:value-of select="@colspan"/>}{*}{<xsl:apply-templates/>} &amp; </xsl:template>  <xsl:template match="td[not(@rowspan)]"> \multicolumn{<xsl:value-of select="@colspan"/>}{l}{<xsl:apply-templates/>} &amp; </xsl:template>  <xsl:template match="td"> \multirow{<xsl:value-of select="@rowspan"/>}{*}{\multicolumn{<xsl:value-of select="@colspan"/>}}{l}{<xsl:apply-templates/>} &amp; </xsl:template> </xsl:stylesheet> 

the problem &amp;s (which become & in output). in latex, need 1 in beginning of third row, spanned cell is. not case in xml table. how can around problem?

enter image description here

<xsl:stylesheet version="2.0"         xmlns:xsl="http://www.w3.org/1999/xsl/transform"         xmlns:xs="http://www.w3.org/2001/xmlschema">  <xsl:output method="text"/>  <xsl:template match="/"> \documentclass{memoir} \usepackage{multirow} \begin{document} <xsl:apply-templates/> \end{document} </xsl:template>  <xsl:template match="table"> <xsl:variable name="noc" select="max(tr/sum(td/(@colspan/number(.),1)[1]))"/> <xsl:text>\begin{tabular}{*{</xsl:text> <xsl:value-of select="$noc"/> <xsl:text>}{l}}&#10;</xsl:text> <xsl:apply-templates select="tr[1]">  <xsl:with-param name="rspans" select="for $i in 1 xs:integer($noc) return 0"/> </xsl:apply-templates> <xsl:text>\end{tabular}</xsl:text> </xsl:template>  <xsl:template match="tr">  <xsl:param name="rspans"/> <xsl:text/>% [<xsl:value-of select="$rspans"/>]  <xsl:variable name="tr" select="."/>  <xsl:for-each select="$rspans">   <xsl:variable name="c" select="position()"/>   <xsl:variable name="td" select="$tr/td[count($rspans[position() &lt;=$c][.=0])]"/>   <xsl:if test=".=0">    <xsl:if test="$td/@rowspan[. &gt; 1]">     <xsl:text>\multirow{</xsl:text>     <xsl:value-of select="$td/@rowspan"/>     <xsl:text>}{*}{</xsl:text>    </xsl:if>    <xsl:apply-templates select="$td"/>    <xsl:if test="$td/@rowspan[. &gt; 1]">}</xsl:if>   </xsl:if>   <xsl:choose>    <xsl:when test=". &gt;1 , position()=last()">&amp;\\&#10;</xsl:when>    <xsl:when test="position()=last()">\\&#10;</xsl:when>    <xsl:otherwise>&amp;</xsl:otherwise>     </xsl:choose>  </xsl:for-each>  <xsl:apply-templates select="following-sibling::tr[1]">   <xsl:with-param name="rspans" select="for $c in 1 count($rspans)    return    ($rspans[$c] +    td[count($rspans[position() &lt;=$c][.=0])]/(@rowspan,1)[1]    -1)"/>  </xsl:apply-templates> </xsl:template>  </xsl:stylesheet> 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -