Xml 如何将子字符串输出到循环XSLT中
我一直在编写一些代码,介绍如何显示或输出一个字符串/代码,该字符串/代码上有一个在循环中被子字符串化的管道delim。查看XML部分,节点有三个值Xml 如何将子字符串输出到循环XSLT中,xml,xslt,substring,Xml,Xslt,Substring,我一直在编写一些代码,介绍如何显示或输出一个字符串/代码,该字符串/代码上有一个在循环中被子字符串化的管道delim。查看XML部分,节点有三个值。问题是当我尝试运行它时,我无法显示的其他值。同样,在我得到子字符串的单词/代码后,我会将它们转换为一个等效的“Enumcode”,比如当它是AAA时,它应该是=3,如果BBB应该是=6,如果CCC=7。我成功地获得了和的转换,分别是'Enumcode'1和'Enumcode'2。提前谢谢 这是我的XSLT代码,我已经尝试过这个解决方案/代码
。问题是当我尝试运行它时,我无法显示
的其他值。同样,在我得到子字符串的单词/代码后,我会将它们转换为一个等效的“Enumcode”,比如当它是AAA时,它应该是=3,如果BBB应该是=6,如果CCC=7。我成功地获得了
和
的转换,分别是'Enumcode'1和'Enumcode'2。提前谢谢
这是我的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/XSL/XMLSchema" exclude-result-prefixes="xs" version="2.0"
xmlns:vb="urn:com.vb/pfile"
xmlns:xsi="http://www.w3.org/2001/XSL/XMLSchema-instance" >
<xsl:output method="text" />
<xsl:template match="/" />
<!-- LineBreak and Delimiter -->
<xsl:variable select="'
'" name="LINE_FEED"/>
<xsl:variable select="'|'" name="PIPE"/>
<!-- Enum codes -->
<xsl:variable select="'1'" name="Enumcode1"/>
<xsl:variable select="'2'" name="Enumcode2"/>
<xsl:variable select="'3'" name="Enumcode3"/>
<xsl:variable select="'6'" name="Enumcode6"/>
<xsl:variable select="'7'" name="Enumcode7"/>
<!-- This is the header -->
<xsl:text>EMPID</xsl:text>
<xsl:value-of select ="$PIPE"/>
<xsl:text>EPtypeID</xsl:text>
<xsl:value-of select ="$PIPE"/>
<xsl:text>EPAmt</xsl:text>
<xsl:value-of select ="$PIPE"/>
<xsl:text>EPPeriod</xsl:text>
<xsl:value-of select ="$PIPE"/>
<xsl:text>CurrID</xsl:text>
<xsl:value-of select ="$PIPE"/>
<xsl:value-of select ="$LINE_FEED"/>
<xsl:variable select="vb:EMPID" name="EmployeeID"/>
<xsl:variable select="vb:work_group/vb:ABase" name="AnBase"/>
<xsl:variable select="vb:work_group/vb:AcBase" name="AccBase"/>
<xsl:variable select="vb:work_group/vb:PPeriod" name="PayPd"/>
<xsl:variable select="vb:work_group/vb:Currency/vb:ID[@vb:type='Currency_ID']" name="CurrencyID"/>
<xsl:if test="$AnBase != ' '">
<EMPLID>
<xsl:value-of select ="$EmployeeID"/>
</EMPLID>
<xsl:value-of select ="$PIPE"/>
<EARN1>
<xsl:value-of select ="$Enumcode1"/>
</EARN1>
<xsl:value-of select ="$PIPE"/>
<Amount>
<xsl:value-of select ="$AnBase"/>
</Amount>
<xsl:value-of select ="$PIPE"/>
<PayPeriod>
<xsl:value-of select ="$PayPd"/>
</PayPeriod>
<xsl:value-of select ="$PIPE"/>
<Currency>
<xsl:value-of select ="$CurrencyID"/>
</Currency>
<xsl:value-of select ="$LINE_FEED"/>
</xsl:if>
<xsl:if test="$AccBase != ' '">
<EMPLID>
<xsl:value-of select ="$EmployeeID"/>
</EMPLID>
<xsl:value-of select ="$PIPE"/>
<EARN1>
<xsl:value-of select ="$Enumcode1"/>
</EARN1>
<xsl:value-of select ="$PIPE"/>
<Amount>
<xsl:value-of select ="$AccBase"/>
</Amount>
<xsl:value-of select ="$PIPE"/>
<PayPeriod>
<xsl:value-of select ="$PayPd"/>
</PayPeriod>
<xsl:value-of select ="$PIPE"/>
<Currency>
<xsl:value-of select ="$CurrencyID"/>
</Currency>
<xsl:value-of select ="$LINE_FEED"/>
</xsl:if>
<xsl:for-each select"vb:earn_group">
<EMPLID>
<xsl:value-of select ="$EmployeeID"/>
</EMPLID>
<!-- Here is the part of my substring -->
<EARN1>
<xsl:choose>
<xsl:when test="substring(vb:ecodewithamt,1,3 = 'AAA' ">
<xsl:value-of select ="$Enumcode3"/>
</xsl:when>
<xsl:when test="substring(vb:ecodewithamt,1,3 = 'BBB' ">
<xsl:value-of select ="$Enumcode6"/>
</xsl:when>
<xsl:when test="substring(vb:ecodewithamt,1,3 = 'CCC' ">
<xsl:value-of select ="$Enumcode7"/>
</xsl:when>
<xsl:otherwise>
<xsl:text></xsl:text>
</xsl:otherwise>
</EARN1>
<!-- End of substring -->
<PayPeriod>
<xsl:value-of select ="$PayPd"/>
</PayPeriod>
<xsl:value-of select ="$PIPE"/>
<Currency>
<xsl:value-of select ="$CurrencyID"/>
</Currency>
<xsl:value-of select ="$LINE_FEED"/>
</xsl:for-each>
</xsl:for-each>
<xsl:stylesheet>
输出应为:
1111|1|3333|AY|XXX
1111|2|2222|AY|XXX
1111|3|9999|AY|XXX
1111|6|8888|AY|XXX
1111|7|7777|AY|XXX
如果我完全忽略您的代码,只关注给定的输入和预期的输出,我会得到: XSLT1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:vb="urn:com.vb/pfile">
<xsl:output method="text" />
<xsl:strip-space elements="*"/>
<xsl:template match="vb:Report_start">
<xsl:variable name="line-begin">
<xsl:value-of select="vb:EMPID"/>
<xsl:text>|</xsl:text>
</xsl:variable>
<xsl:variable name="line-end">
<xsl:text>|</xsl:text>
<xsl:value-of select="vb:work_group/vb:PPeriod"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="vb:work_group/vb:Currency/vb:ID[@vb:type='Currency_ID']"/>
<xsl:text> </xsl:text>
</xsl:variable>
<!-- PART A -->
<xsl:value-of select="$line-begin"/>
<xsl:text>1|</xsl:text>
<xsl:value-of select="vb:work_group/vb:ABase"/>
<xsl:value-of select="$line-end"/>
<xsl:value-of select="$line-begin"/>
<xsl:text>2|</xsl:text>
<xsl:value-of select="vb:work_group/vb:AcBase"/>
<xsl:value-of select="$line-end"/>
<!-- PART B -->
<xsl:for-each select="vb:earn_group/vb:ecodewithamt">
<xsl:variable name="code" select="substring-before(., '|')" />
<xsl:value-of select="$line-begin"/>
<xsl:choose>
<xsl:when test="$code='AAA'">3</xsl:when>
<xsl:when test="$code='BBB'">6</xsl:when>
<xsl:when test="$code='CCC'">7</xsl:when>
</xsl:choose>
<xsl:text>|</xsl:text>
<xsl:value-of select="substring-after(., '|')" />
<xsl:value-of select="$line-end"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
这是不可能的。你的代码充满了错误,你对你正在努力解决的问题的解释也不清楚。谢谢你,伙计,我稍后会尝试这个。问题,在
选择上下文节点之前和之后的子字符串的参数上,.的用法是什么
1111|1|3333|AY|XXX
1111|2|2222|AY|XXX
1111|3|9999|AY|XXX
1111|6|8888|AY|XXX
1111|7|7777|AY|XXX
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:vb="urn:com.vb/pfile">
<xsl:output method="text" />
<xsl:strip-space elements="*"/>
<xsl:template match="vb:Report_start">
<xsl:variable name="line-begin">
<xsl:value-of select="vb:EMPID"/>
<xsl:text>|</xsl:text>
</xsl:variable>
<xsl:variable name="line-end">
<xsl:text>|</xsl:text>
<xsl:value-of select="vb:work_group/vb:PPeriod"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="vb:work_group/vb:Currency/vb:ID[@vb:type='Currency_ID']"/>
<xsl:text> </xsl:text>
</xsl:variable>
<!-- PART A -->
<xsl:value-of select="$line-begin"/>
<xsl:text>1|</xsl:text>
<xsl:value-of select="vb:work_group/vb:ABase"/>
<xsl:value-of select="$line-end"/>
<xsl:value-of select="$line-begin"/>
<xsl:text>2|</xsl:text>
<xsl:value-of select="vb:work_group/vb:AcBase"/>
<xsl:value-of select="$line-end"/>
<!-- PART B -->
<xsl:for-each select="vb:earn_group/vb:ecodewithamt">
<xsl:variable name="code" select="substring-before(., '|')" />
<xsl:value-of select="$line-begin"/>
<xsl:choose>
<xsl:when test="$code='AAA'">3</xsl:when>
<xsl:when test="$code='BBB'">6</xsl:when>
<xsl:when test="$code='CCC'">7</xsl:when>
</xsl:choose>
<xsl:text>|</xsl:text>
<xsl:value-of select="substring-after(., '|')" />
<xsl:value-of select="$line-end"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
1111|1|3333|AY|XXX
1111|2|2222|AY|XXX
1111|3|9999|AY|XXX
1111|6|8888|AY|XXX
1111|7|7777|AY|XXX