xml - 在将 XML 转换为文本时,第二行在 XSLT 中移动了两个选项卡
问题描述
我有下面的 xml,我写了一个 XSLT 来将输出转换为文本格式,但是在病房的第二行,输出移动了两个选项卡,我不知道为什么。任何人都可以帮忙吗?
xslt有什么问题吗?是什么让第二行发生了变化?
<?xml version="1.0" encoding="UTF-8"?>
<document>
<businessobjects>
<entry>
<HeaderLine>
<HeaderRow>H</HeaderRow>
<HeaderBusinessUnit/>
<CurrentTime>0704202004:47:43</CurrentTime>
<TotalAmountCredit>-6.084732570000003E6</TotalAmountCredit>
<TotalAmountDebit>6.194972230000004E6</TotalAmountDebit>
<LineEntries>948</LineEntries>
</HeaderLine>
<LineDetails>
<Line>L</Line>
<HeaderBusinessUnit/>
<FinancialYear>2020</FinancialYear>
<Period>5</Period>
<EndDate>20200101</EndDate>
<Period>5</Period>
<GLBusinessUnit>UTEP1</GLBusinessUnit>
<GLAccount/>
<EntryType>DEBITJOURNALENTRY</EntryType>
<Amount>10000</Amount>
<Currency>USD</Currency>
<CostCenter>14026800</CostCenter>
<ContractCode>L0498</ContractCode>
<ContractName>Base Case - AC</ContractName>
<ContractLineCode>1886</ContractLineCode>
<PostingCode>1</PostingCode>
</LineDetails>
</entry>
</businessobjects>
</document>
使用 XSLT
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name='newline'>
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:template match="businessobjects">
<xsl:for-each select="entry">
<xsl:for-each select="HeaderLine">
<xsl:value-of select="concat(HeaderRow,'|',HeaderBusinessUnit,'|',
CurrentTime,'|',TotalAmountCredit,'|',
TotalAmountDebit,'|',LineEntries,$newline)"/>
</xsl:for-each>
<xsl:for-each select="LineDetails">
<xsl:value-of select="concat(Line,'|',HeaderBusinessUnit,'|',FinancialYear,
'|',Period,'|',EndDate,'|',GLBusinessUnit,'|',GLAccount,'|',EntryType,'|',Amount,'|',Currency,'|',CostCenter,'|',ContractCode,'|',ContractName,'|',ContractLineCode,'|',PostingCode,$newline)"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
输出
H||0704202004:47:43|-6.084732570000003E6|6.194972230000004E6|948
L||2020|5|20200101|UTEP1||DEBITJOURNALENTRY|10000|USD|14026800|L0498|Base Case - AC|1886|1
解决方案
但在病房的第二行,输出移动了两个选项卡,我不知道为什么。
因为您的$newline
变量包含一个换行符和两个制表符:
<xsl:variable name='newline'>
<xsl:text>
</xsl:text>
</xsl:variable>
将其更改为:
<xsl:variable name='newline'>
<xsl:text>
</xsl:text>
</xsl:variable>
或(最好是恕我直言)摆脱变量并使用您想要的确切换行符,例如
<xsl:text> </xsl:text>
推荐阅读
- python - 使用 PCA sklearn 和 TensorFlow 实现管道
- python - 我的 break 语句不能在带有 if 语句的 while 循环中工作?
- android-recyclerview - 嵌套在 ViewPAge 上的 RecycleView
- java - 为什么在创建跨团队依赖时使用枚举?
- url - 我可以让 sub.domain.tld 和 *.sub.domain.tld 解析到不同的地方吗?
- javascript - 下拉显示乱序
- yii2 - Yii2:在分页器上呈现页面大小选择器的简单方法
- typescript - 如何创建泛型类型并将其传递给调用站点的函数?
- laravel - Laravel 数据表 - 无效的 JSON 响应
- python - 在模块中使用 lambda 函数比较值