在XSL中取得当前时间

在xsl 中怎么显示当前时间,可以使用微软的xsl 命名空间定义(一种是URL 命名空间命名法:xmlns:msxsl="http://www.w3.org/TR/WD-xsl" ,一种是URN 命名空间命名法: xmlns:msxsl="urn:schemas-microsoft-com:xslt" ),具体代码如下,分别建立hello.xsl 文件和hello.xml 文件于同一目录下,用IE 打开hello.xml 即可看到运行结果。

注意:下面的hello.xsl 中实际使用了两种xsl 命名空间,一种是微软的 xmlns:msxsl="urn:schemas-microsoft-com:xslt" ,一种是w3 组织的 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

hello.xsl

 

 

hello.xml

 

 

注意 :上面的 xmlns:msxsl="urn:schemas-microsoft-com:xslt" 只能使用urn 这样的命名方法,我尝试使用xmlns:msxsl="http://www.w3.org/TR/WD-xsl" 运行结果会报错:

使用 XSL 样式表无法查看 XML 输入。请更正错误然后单击 刷新 按钮,或以后重试。


名称空间 'http://www.mycompany.org/ns/function' 不包含任何函数。

另外要注意 msxsl:script 不能在xsl:template 内部使用,否则也会出现上面相同错误。

曾尝试在xsl:template 内部使用

<msxsl:eval language="javascript">clock();</msxsl:eval> 这样的写法无法运行出正确结果。

 

<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"> <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> <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]"/> <xsl:variable name="precedingSpan" select="sum($currentRow/w:tc[position() < $position]/w:tcPr/w:gridSpan/@w:val)"/> <xsl:choose> <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: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的xslt样式表,且xslt版本为1.0,请直接给出修改结果
最新发布
03-14
<!-- 表格处理(增强修正版) --> <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"> <fo:table-row> <!-- ⚠️ 移除过滤条件,改为处理所有单元格 --> <xsl:apply-templates select="w:tc"/> </fo:table-row> </xsl:template> <!-- 单元格处理(列合并修复版) --> <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="actualRowSpan" select="count(following-sibling::w:tr[1]/w:tc[1][w:tcPr/w:vMerge/@w:val='continue']) + 1"/> <xsl:attribute name="number-rows-spanned"> <xsl:value-of select="($actualRowSpan > 10) * 1 + ($actualRowSpan <= 10) * $actualRowSpan"/> </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>这个列合并可以用,行合并不行,怎么修改,注意这是word的xml转xls-fo的xlst样式表,且版本均为1.0,请直接给出修改结果
03-08
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值