XSLT 1.0 Kludge 清理 [英] XSLT 1.0 Kludge cleanup

查看:23
本文介绍了XSLT 1.0 Kludge 清理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在打印一条反向字体(黑色背景,白色文本),分布在我的收据带(41 个字符)的宽度上.我有功能代码,但我想知道是否有更好的方法来做到这一点:

I am printing a line in reverse font (black background, white text), spread over the width of my receipt tape (41 characters). I have functional code, but I am wondering if there is a better way to do this:

这是我现有的代码:

<text lang="en" align="center" smooth="true" reverse="1"><xsl:value-of select="substring($spaces21, 1, (string-length($spaces21) - ((string-length(SavingsSegment) div 2) + string-length(SavingsSegment) mod 2)))"/>
  <xsl:value-of select="SavingsSegment"/><xsl:value-of select="substring($spaces21, 1, (string-length($spaces21) - ((string-length(SavingsSegment) div 2) + string-length(SavingsSegment) mod 2)))"/>
</text>

此代码生成此 XML:

This code results in this XML:

 <text lang="en" align="center" smooth="true" reverse="1" xmlns="">             YOU SAVED $2.00             </text>

说明:spaces21 是一个包含 21 个空格的文本字段,如果这还不是很明显的话.

Clarification: spaces21 is a text field with 21 spaces in it, if that wasn't already obvious.

无论我输入的值是多少,xml 都能正确打印($1,275,824.00 和 $2.00 一样有效).

The xml prints correctly, no matter the value I put in ($1,275,824.00 worked just as well as $2.00).

我的问题是,这是有史以来最笨拙的笨拙笨拙.有没有办法以更简洁的方式做到这一点?

My problem is that this is the kludgiest kludge that ever did kludge. Is there a way to do this in a cleaner manner?

谢谢!

推荐答案

如果您使用 libxsltXalan 或其他支持 EXSLT 的处理器 str:align()str:padding() 扩展函数,那么你可以简单地做:

If you're using libxslt or Xalan or another processor that supports the EXSLT str:align() and str:padding() extension functions, then you could do simply:

<text>
    <xsl:value-of select="str:align(SavingsSegment, str:padding(41, ' '), 'center')"/>
</text> 

<小时>

在纯 XSLT 1.0 中做,我相信这样会更优雅:


To do it in pure XSLT 1.0, I believe this would be more elegant:

<xsl:variable name="spaces21" select="'                     '"/>
<xsl:variable name="pad" select="(41 - string-length(SavingsSegment)) div 2"/>
<text>
    <xsl:value-of select="substring($spaces21, 1, floor($pad))"/>
    <xsl:value-of select="SavingsSegment"/>
    <xsl:value-of select="substring($spaces21, 1, ceiling($pad))"/>
</text> 

这篇关于XSLT 1.0 Kludge 清理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆