工作日软件中的xtt:fixedLength问题

时间:2017-12-26 16:59:36

标签: xml xslt xslt-2.0 workday-api

我正在尝试将XML转换为固定宽度文件,但param import json a= { u'Status': { u'display_name': u'Status', u'is_updatable': True, u'type': u'TEXT', u'val': u'Paying', u'source': u'API' }, u'Create Date': { u'display_name': u'Create Date', u'is_updatable': True, u'type': u'DATE', u'val': u'2017-09-20', u'source': u'API' }, u'Total # of Projects': { u'display_name': u'Total # of Projects', u'is_updatable': True, u'type': u'TEXT', u'val': u'53', u'source': u'Pixel' } } b=json.dumps(a) #String to json print (b) c=json.loads(b) print (c) 不能用于我的XSLT转换。这是我的XSLT

xtt:fixedLength

我得到的输出是

0001013507738HALLERICA01050

我需要这样的东西

0001013507738HALL(此处有26个额外空格)ERICA(此处有10个额外空格)010 50

我的<?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> 无效。请帮帮我。

由于

1 个答案:

答案 0 :(得分: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>

<强>输出

  

短[5 chars]太多LJust Right

<强> paddingCharacter

<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>

<强>输出

  

短-----太多了......

Reference