我有这个XML源:
<HEADER>
<ODL_CODE>589146586</ODL_CODE>
<ADR_CODE>154116515</ADR_CODE>
<MNV_HER>EUR</MNV_HER>
<IKS>
<TYPE_CU>BY</TYPE_CU>
<ID_CU>549745</ID_CU>
<NAME>Company name</NAME>
<ADDRESS>Street 123, City</ADDRESS>
<TEL>+45 789 632 548</TEL>
<MAIL>[email protected]</MAIL>
</IKS>
<IKS>
<TYPE_CU>IV</TYPE_CU>
<ID_CU>7894156</ID_CU>
<NAME>Company name #2</NAME>
<ADDRESS>Street 123, City #2</ADDRESS>
<TEL>+45 789 632 548 #2</TEL>
<MAIL>[email protected] #2</MAIL>
</IKS>
</HEADER>
我想要这个输出:
<HEADER>
<ODL_CODE>589146586</ODL_CODE>
<ADR_CODE>154116515</ADR_CODE>
<MNV_HER>EUR</MNV_HER>
<IKS>
<TYPE_CU>BY</TYPE_CU>
<ID_CU>549745</ID_CU>
<NAME>Company name</NAME>
<ADDRESS>Street 123, City</ADDRESS>
<TEL>+45 789 632 548</TEL>
<MAIL>[email protected]</MAIL>
</IKS>
<IKS>
<TYPE_CU>IV</TYPE_CU>
<ID_CU>7894156</ID_CU>
<NAME>Company name #2</NAME>
<ADDRESS>Street 123, City #2</ADDRESS>
<TEL>+45 789 632 548 #2</TEL>
<MAIL>[email protected] #2</MAIL>
</IKS>
<POZN_1>Name: Company name #2, Street: Street 123, City #2, TEL: +45 789 632 548 #2</POZN_1>
</HEADER>
如何在XSLT中编写它?我在“value-of select”中尝试连接函数,但我在代码TYPE_CU,ID_CU等中遇到了2个元素的问题。它必须在TYPE_CU中通过“IV”进行识别,但我不知道为什么。
您需要显示您尝试为值的串联执行的代码:
使用此代码希望对您有所帮助:
<?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">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="IKS[TYPE_CU='IV']">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
<POZN_1><xsl:value-of select="concat('Name: ' , NAME, ', Street: ', ADDRESS, ', TEL: ', TEL)"/></POZN_1>
</xsl:template>
</xsl:stylesheet>