2

我正在尝试将我的 XML 转换为固定宽度的文件,但参数xtt:fixedLength不适用于我的 XSLT 转换。这是我的 XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
    version="2.0" xmlns:wd="urn:com.workday.report/INT069_REP-Emp_File"
    xmlns:lancet="http://example.com/mf" 
    xmlns:xtt="urn:com.workday/xtt" xmlns:etv="urn:com.workday/etv">

    <xsl:variable name="lineFeeder" select="'&#13;&#10;'" />
    <xsl:template match="/wd:Report_Data">
        <root>
            <xsl:for-each select="wd:Report_Entry">
                <Company_code xtt:fixedLength="4" xtt:paddingCharacter="0" xtt:align="right">
                    <xsl:value-of select="format-number(wd:Company, '0000')" />
                </Company_code>
                <Employee_ID xtt:fixedLength="9" xtt:paddingCharacter="0" xtt:align="right">
                    <xsl:value-of select="format-number(wd:Employee_ID, '000000000')" />
                </Employee_ID>
                <Last_Name xtt:fixedLength="30">
                    <xsl:value-of select="lancet:stripSpecialChars(replace(normalize-unicode(translate(wd:Last_Name, ',', ''), 'NFKD'), '⁄', '/'))" />
                </Last_Name>
                <First_name xtt:fixedLength="15">
                    <xsl:value-of select="lancet:stripSpecialChars(replace(normalize-unicode(translate(wd:First_Name, ',', ''), 'NFKD'), '⁄', '/'))" />
                </First_name>
                <Status xtt:fixedLength="2">
                    <xsl:value-of select="wd:status" />
                </Status>
                <Cost_Center xtt:fixedLength="5">
                    <xsl:value-of select="wd:Cost_Center" />
                </Cost_Center>
                <xsl:text>&#x0A;</xsl:text>
            </xsl:for-each>
        </root>
    </xsl:template>

    <xsl:function name="lancet:stripSpecialChars">
        <xsl:param name="string" />
        <xsl:variable name="AllowedSymbols" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789()*%$#@!~&lt;&gt;,.?[]=- +   /\ '" />
        <xsl:value-of select="translate($string, translate($string, $AllowedSymbols, ''), ' ')" />
    </xsl:function>
</xsl:stylesheet>

我得到的输出是

0001013507738HALLERICA01050

我需要这样的东西

0001013507738HALL(此处多出 26 个空格) ERICA(此处多出 10 个空格) 010 50

xtt:FixedLength的不工作。这个你能帮我吗。

谢谢

4

1 回答 1

1

请从每个标签中删除 xtt:align="right",如下所示

<Company_code xtt:fixedLength="4" xtt:paddingCharacter="0">
   <xsl:value-of select="format-number(wd:Company, '0000')" />
</Company_code>

根据工作日文件,

对齐

<Sample xtt:align="right">
  <item xtt:fixedLength="10">Short</item>
  <item xtt:fixedLength="10">Much Too Long</item>
  <item xtt:fixedLength="10">Just Right</item>
</Sample>

输出

ShortMuch Too LJust Right


固定长度

<Sample>
  <item xtt:fixedLength="10">Short</item>
  <item xtt:fixedLength="10">Much Too Long</item>
  <item xtt:fixedLength="10">Just Right</item>
</Sample>

输出

Short[5 chars]Much Too LJust Right


填充字符

<Sample xtt:paddingCharacter="-">
  <item xtt:fixedLength="10">Short</item>
  <item xtt:fixedLength="10">Much Too Long</item>
  <item xtt:fixedLength="10">Just Right</item>
</Sample>

输出

Short-----Much Too L恰到好处

参考

于 2017-12-31T19:00:31.677 回答