我要做的是将模板应用于所有
AccountNo
元素并对其排序。
然后匹配
账户编号
并输出条目。。。
XSLT 2.0
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<xsl:apply-templates select=".//AccountNo">
<xsl:sort data-type="number"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="AccountNo">
<xsl:value-of select="string-join((.,../../(FirstName,LastName,ContactNo)),'	')"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
输出
1000 Ramesh Patel 1234567890
1001 Viraj Shah 4567890989
1002 Ramesh Patel 1234567890
1003 Kapil Sharma 3456789320
1004 Ramesh Patel 1234567890
1005 Kapil Sharma 3456789320
工作小提琴:
http://xsltfiddle.liberty-development.net/948Fn5o
更新
由于输出应该位于固定字段中,因此我建议创建一个函数,用于在字符串中填充空格以适应字段。这将允许您保证字段的宽度与您想要的宽度完全一致。
实例
XSLT 2.0
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:l="local">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<xsl:apply-templates select=".//AccountNo">
<xsl:sort data-type="number"/>
</xsl:apply-templates>
</xsl:template>
<!--Note: If the string to pad is longer than the width specified, the string
will be truncated to fit the width.-->
<xsl:function name="l:pad">
<xsl:param name="toPad" as="xs:string?"/>
<xsl:param name="width" as="xs:integer"/>
<xsl:variable name="padding"
select="for $x in 1 to $width - string-length(normalize-space($toPad)) return ' '"/>
<xsl:value-of
select="substring(
concat(normalize-space($toPad), string-join($padding,'')),
1,$width)"/>
</xsl:function>
<xsl:template match="AccountNo">
<xsl:value-of select="(
l:pad(.,8),
../../(
l:pad(FirstName,8),
l:pad(LastName,8),
l:pad(ContactNo,10)
),'
')"/>
</xsl:template>
</xsl:stylesheet>
更新的小提琴:
http://xsltfiddle.liberty-development.net/948Fn5o/3