Xml XSL转换,输出为文本
使用XSL转换。在XSLT1.0中没有与printf(“%30s”,something)一般等价的东西。我通常使用的技巧是创建一个包含长字符串空格的变量,然后获取适当长度的子字符串Xml XSL转换,输出为文本,xml,xslt,Xml,Xslt,使用XSL转换。在XSLT1.0中没有与printf(“%30s”,something)一般等价的东西。我通常使用的技巧是创建一个包含长字符串空格的变量,然后获取适当长度的子字符串 CHTP CLS DEBY SSN: *****4512 115 Z 88TH UL #226-F DOB: 1999-01-08 ARVADA, CO 80004
CHTP CLS DEBY SSN: *****4512
115 Z 88TH UL #226-F DOB: 1999-01-08
ARVADA, CO 80004
Gender: M
Eye Color: Blue Height: 182
Hair Color: Brown Weight: 69
你的输入是什么样的?请看-您已经完成了所有这些操作了吗?输入是XML文件。我能够从XML中提取信息,但无法以上述方式显示。P.S制表符分隔的部分…我不确定。xsl中是否有任何函数允许您这样做?@avinashchavan,使问题成为一个好问题。。您需要提供输入XML(一个示例,而不是实时的),您也尝试过什么。。“这是一个很好的做法,@avinashchavan,这里是你的问题。。我们不知道您的XML到底是什么样子的!多布从哪里来?性别从何而来?你需要详细说明,但要让问题更简单易懂!!@婴儿程序员“Aravind”能够以文本格式生成输出,但我无法执行格式化(即固定间隔制表符分隔文本)部分。请检查。我已经更新了问题。加油!!!我已经更新了我的问题。请重新打开它@avinashchavan我已经投票决定重新开放,但在这真正发生之前,它需要几个不同的人的投票。没有问题,伙计。谢谢你的帮助!!!
CHTP CLS DEBY SSN: *****4512
115 Z 88TH UL #226-F DOB: 1999-01-08
ARVADA, CO 80004
Gender: M
Eye Color: Blue Height: 182
Hair Color: Brown Weight: 69
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="no" omit-xml-declaration="yes" method="text" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="spaces"
select="' '"/>
<xsl:template match="main">
<xsl:call-template name="print-padded">
<xsl:with-param name="str" select="name" />
<xsl:with-param name="width" select="43" />
</xsl:call-template>
<xsl:text>SSN: </xsl:text>
<xsl:value-of select="ssn" />
<xsl:text>
</xsl:text>
<xsl:call-template name="print-padded">
<xsl:with-param name="str" select="address1" />
<xsl:with-param name="width" select="53" />
</xsl:call-template>
<xsl:text>DOB: </xsl:text>
<xsl:value-of select="dob" />
<xsl:text>
</xsl:text>
<!-- and so on for the other elements -->
</xsl:template>
<xsl:template name="print-padded">
<xsl:param name="str" select="''" />
<xsl:param name="width" select="0" />
<xsl:value-of select="$str" />
<xsl:value-of select="substring($spaces, 1, $width - string-length($str))" />
</xsl:template>
</xsl:stylesheet>
<xsl:variable name="stars" select="'*******************'" />
<xsl:value-of select="substring($stars, 1, string-length(ssn) - 4)" />
<xsl:value-of select="substring(ssn, string-length(ssn) - 4)" />