xsl 定义variable

===========================x1.xsl:
    <!-- convert an attachment_id of a image to image filename
    @param    id (type:string, required) attachment_id
    @param    type (type:string, required) image type, eg Gws, Pdt, Logo
    @param    name (type:string, required) original filename with file extension
    @param    entity_id (type:string, optional) entity_id to put as filename
    -->
    <xsl:template name="attachmentid2filename ">
        <xsl:param name="id"/>
        <xsl:param name="type"/>
        <xsl:param name="mime_type"/>
        <xsl:param name="name" select="'image.bin'"/>
        <xsl:param name="entity_id" select="''"/>

        <xsl:variable name="prefix">
            <xsl:value-of select="substring($type,1,1)"/>
        </xsl:variable>

        <xsl:variable name="aid">
            <xsl:choose>
                <xsl:when test="$entity_id != ''">
                    <xsl:value-of select="$entity_id"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="substring($id+10000000000,2,10)"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="ext">
            <xsl:call-template name="mime2ext">
                <xsl:with-param name="mime_type" select="$mime_type"/>
            </xsl:call-template>
            <!--
            <xsl:variable name="tmpext">
                <xsl:value-of select="translate(substring-after(substring($name,string-length($name)-4),'.'),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
            </xsl:variable>
            <xsl:choose>
                <xsl:when test="$tmpext = 'jpeg'">
                    <xsl:value-of select="'jpg'"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$tmpext"/>
                </xsl:otherwise>
            </xsl:choose>
            -->
        </xsl:variable>
        <xsl:variable name="filename">
            <xsl:value-of select="concat($prefix,$aid,'.',$ext)"/>
        </xsl:variable>
        <xsl:value-of select="$filename"/>
    </xsl:template>



===========================x2.xsl: how to call
 <xsl:variable name="filename">
    <xsl:call-template name="attachmentid2filename ">
           <xsl:with-param name="id" select="AttachmentID/text()"/>
           <xsl:with-param name="type" select="'ContactImage'"/>
           <xsl:with-param name="mime_type" select="MimeType/text()"/>
           <xsl:with-param name="name" select="FileName/text()"/>
    </xsl:call-template>
</xsl:variable>

=============================xml

      <ContactImage type="Group">
          <FileName type="String" lang="en">144426707.jpg</FileName>
          <AttachmentID type="String" lang="en">144426707</AttachmentID>
          <MimeType type="String" lang="en">image/pjpeg</MimeType>
          <ImageSize type="String" lang="en">148408</ImageSize>
      </ContactImage>

<xsl:template match="w:tc"><fo:table-cell border="1pt solid black"padding="2pt"display-align="center"><xsl:variable name="totalCols"select="count(ancestor::w:tbl/w:tblGrid/w:gridCol)"/><xsl:variable name="precedingSpanSum"><xsl:choose><xsl:when test="preceding-sibling::w:tc"><xsl:value-of select="sum(preceding-sibling::w:tc/w:tcPr/w:gridSpan/@w:val) + count(preceding-sibling::w:tc[not(w:tcPr/w:gridSpan)])"/></xsl:when><xsl:otherwise>0</xsl:otherwise></xsl:choose></xsl:variable><xsl:if test="w:tcPr/w:gridSpan"><xsl:variable name="declaredSpan"select="w:tcPr/w:gridSpan/@w:val"/><xsl:variable name="remainingCols"select="$totalCols - $precedingSpanSum"/><xsl:attribute name="number-columns-spanned"><xsl:choose><xsl:when test="$declaredSpan > $remainingCols"><xsl:value-of select="$remainingCols"/></xsl:when><xsl:otherwise><xsl:value-of select="$declaredSpan"/></xsl:otherwise></xsl:choose></xsl:attribute></xsl:if><!--修正的行合并逻辑--><xsl:if test="w:tcPr/w:vMerge[@w:val='restart']"><xsl:variable name="currentPos"select="count(preceding-sibling::w:tc) + 1"/><xsl:variable name="rowSpan"><xsl:call-template name="calculateRowSpan"><!--修正点1:直接取后续所有行--><xsl:with-param name="remainingRows"select="../following-sibling::w:tr"/><xsl:with-param name="position"select="$currentPos"/><xsl:with-param name="count"select="1"/></xsl:call-template></xsl:variable><xsl:attribute name="number-rows-spanned"><xsl:value-of select="$rowSpan"/></xsl:attribute></xsl:if><fo:block linefeed-treatment="ignore"white-space-collapse="true"><xsl:apply-templates select=".//w:p"/></fo:block></fo:table-cell></xsl:template><!--新增递归模板--><xsl:template name="calculateRowSpan"><xsl:param name="remainingRows"/><xsl:param name="position"/><xsl:param name="count"/><xsl:choose><!--修正点2:增加空行判断--><xsl:when test="count($remainingRows) = 0"><xsl:value-of select="$count"/></xsl:when><xsl:otherwise><xsl:variable name="currentRow"select="$remainingRows[1]"/><xsl:variable name="targetCell"select="$currentRow/w:tc[$position]"/><!--修正点3:处理单元格位置偏移--><xsl:variable name="precedingSpan"select="sum($currentRow/w:tc[position() < $position]/w:tcPr/w:gridSpan/@w:val)"/><xsl:choose><!--修正点4:精准定位合并目标单元格--><xsl:when test="$targetCell/w:tcPr/w:vMerge[@w:val='continue'] and ($position - $precedingSpan) <= count($currentRow/w:tc)"><xsl:call-template name="calculateRowSpan"><xsl:with-param name="remainingRows"select="$remainingRows[position() > 1]"/><xsl:with-param name="position"select="$position"/><xsl:with-param name="count"select="$count + 1"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:value-of select="$count"/></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></xsl:template>这个行合并失效,一定要注意这是word的xml转xls-fo的xlst样式表,且xsl和xml版本均为1.0,请直接给出修改结果
03-11
<xsl:template match=“w:tc”><fo:table-cell border=“1pt solid black"padding=“2pt"display-align=“center”><xsl:variable name=“totalCols"select=“count(ancestor::w:tbl/w:tblGrid/w:gridCol)”/><xsl:variable name=“precedingSpanSum”>xsl:choose<xsl:when test=“preceding-sibling::w:tc”><xsl:value-of select=“sum(preceding-sibling::w:tc/w:tcPr/w:gridSpan/@w:val) + count(preceding-sibling::w:tc[not(w:tcPr/w:gridSpan)])”/></xsl:when>xsl:otherwise0</xsl:otherwise></xsl:choose></xsl:variable><xsl:if test=“w:tcPr/w:gridSpan”><xsl:variable name=“declaredSpan"select=“w:tcPr/w:gridSpan/@w:val”/><xsl:variable name=“remainingCols"select=”$totalCols - $precedingSpanSum”/><xsl:attribute name=“number-columns-spanned”>xsl:choose<xsl:when test=”$declaredSpan > $remainingCols”><xsl:value-of select=”$remainingCols"/></xsl:when>xsl:otherwise<xsl:value-of select=“$declaredSpan”/></xsl:otherwise></xsl:choose></xsl:attribute></xsl:if><!–修正的行合并逻辑–><xsl:if test=“w:tcPr/w:vMerge[@w:val=‘restart’]”><xsl:variable name=“currentPos"select=“count(preceding-sibling::w:tc) + 1”/><xsl:variable name=“rowSpan”><xsl:call-template name=“calculateRowSpan”><!–修正点1:直接取后续所有行–><xsl:with-param name=“remainingRows"select=”…/following-sibling::w:tr”/><xsl:with-param name=“position"select=”$currentPos"/><xsl:with-param name=“count"select=“1”/></xsl:call-template></xsl:variable><xsl:attribute name=“number-rows-spanned”><xsl:value-of select=”$rowSpan"/></xsl:attribute></xsl:if><fo:block linefeed-treatment=“ignore"white-space-collapse=“true”><xsl:apply-templates select=”.//w:p"/></fo:block></fo:table-cell></xsl:template><!–新增递归模板–><xsl:template name=“calculateRowSpan”><xsl:param name=“remainingRows”/><xsl:param name=“position”/><xsl:param name=“count”/>xsl:choose<!–修正点2:增加空行判断–><xsl:when test=“count($remainingRows) = 0”><xsl:value-of select=“$count”/></xsl:when>xsl:otherwise<xsl:variable name=“currentRow"select=”$remainingRows[1]“/><xsl:variable name=“targetCell"select=”$currentRow/w:tc[$position]”/><!–修正点3:处理单元格位置偏移–><xsl:variable name=“precedingSpan"select=“sum($currentRow/w:tc[position() < $position]/w:tcPr/w:gridSpan/@w:val)”/>xsl:choose<!–修正点4:精准定位合并目标单元格–><xsl:when test=”$targetCell/w:tcPr/w:vMerge[@w:val=‘continue’] and ($position - $precedingSpan) <= count($currentRow/w:tc)“><xsl:call-template name=“calculateRowSpan”><xsl:with-param name=“remainingRows"select=”$remainingRows[position() > 1]”/><xsl:with-param name=“position"select=”$position"/><xsl:with-param name=“count"select=”$count + 1"/></xsl:call-template></xsl:when>xsl:otherwise<xsl:value-of select=“$count”/></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></xsl:template>修改这段样式表,使表格的行合并单元格生效,一定要注意这是word的xml转xls-fo的xlst样式表,且xsl和xml版本均为1.0,请直接给出修改结果
最新发布
03-12
<xsl:template match="w:tbl"> <xsl:variable name="colCount" select="count(w:tblGrid/w:gridCol)"/> <fo:table table-layout="fixed" width="100%" border-collapse="collapse"> <!-- 生成精确列定义 --> <xsl:for-each select="w:tblGrid/w:gridCol"> <fo:table-column column-width="{@w:w div 20}pt"/> </xsl:for-each> <fo:table-body> <!-- 列溢出检测逻辑保持不变 --> <xsl:if test="count(w:tr[1]/w:tc) > $colCount"> <fo:table-row> <fo:table-cell number-columns-spanned="{$colCount}"> <fo:block color="red">表格列数溢出警告</fo:block> </fo:table-cell> </fo:table-row> </xsl:if> <xsl:apply-templates select="w:tr"/> </fo:table-body> </fo:table> </xsl:template> <xsl:template match="w:tr"> <tr> <xsl:apply-templates select="w:tc"/> </tr> </xsl:template> <xsl:template match="w:tc"> <xsl:variable name="pos" select="count(preceding-sibling::w:tc) + 1"/> <xsl:variable name="vMergeStart" select="w:tcPr/w:vMerge/@w:val = 'restart' or (w:tcPr/w:vMerge and not(@w:val))"/> <xsl:variable name="rowspan"> <xsl:choose> <xsl:when test="$vMergeStart"> <xsl:call-template name="calculateRowspan"> <xsl:with-param name="currentRow" select="../following-sibling::w:tr"/> <xsl:with-param name="columnPos" select="$pos"/> <xsl:with-param name="count" select="1"/> </xsl:call-template> </xsl:when> <xsl:otherwise>1</xsl:otherwise> </xsl:choose> </xsl:variable> <td> <xsl:if test="$rowspan > 1"> <xsl:attribute name="rowspan"> <xsl:value-of select="$rowspan"/> </xsl:attribute> </xsl:if> </td> </xsl:template> <xsl:template name="calculateRowspan"> <xsl:param name="currentRow"/> <xsl:param name="columnPos"/> <xsl:param name="count"/> <xsl:choose> <xsl:when test="$currentRow[1]/w:tc[position() = $columnPos]/w:tcPr/w:vMerge"> <xsl:call-template name="calculateRowspan"> <xsl:with-param name="currentRow" select="$currentRow[position() > 1]"/> <xsl:with-param name="columnPos" select="$columnPos"/> <xsl:with-param name="count" select="$count + 1"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$count"/> </xsl:otherwise> </xsl:choose> </xsl:template>我这个word的xml转xls-fo的xlst样式表,且xsl和xml版本均为1.0,表格处理这块不能用,设计行或者列单元格合并有问题,请修改完善,一定要注意这是word的xml转xls-fo的xlst样式表,且xsl和xml版本均为1.0,请直接给出修改结果
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值