【发布时间】:2023-03-18 18:50:01
【问题描述】:
我正在尝试替换最后出现的 '.'使用 XSLT (xslt 1.0 xsltproc) 时带有“/”字符的字符。我该怎么做?
输入.xml
<testng-results>
<suite>
<test>
<class name="system.apps.webdriver.tests.crm.mot.CreateTerritoryProposalTest">
<test-method status="PASS" started-at="2019-02-07T18:24:47Z" name="initTest">
</test-method>
<test-method status="FAIL" started-at="2019-02-07T18:24:47Z" name="ActListsForContactShowsContactRelatedTasksTest">
</test-method>
</class>
</test>
</suite>
</testng-results>
当前 XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<Suite>
<xsl:for-each select="testng-results/suite/test/class/test-method">
<Test>
<Result_Path> <xsl:value-of select="concat('testngreports/', ../@name, '/', @name)"/> </Result_Path>
</Test>
</xsl:for-each>
</Suite>
</xsl:template>
</xsl:stylesheet>
预期结果 XML:
<?xml version="1.0" encoding="UTF-8"?>
<Suite>
<Test>
<Result_Path>testngreports/system.apps.webdriver.tests.crm.mot/CreateTerritoryProposalTest/initTest</Result_Path>
</Test>
<Test>
<Result_Path>testngreports/system.apps.webdriver.tests.crm.mot/CreateTerritoryProposalTest/ActListsForContactShowsContactRelatedTasksTest</Result_Path>
</Test>
</Suite>
当前输出 XML:
<?xml version="1.0" encoding="UTF-8"?>
<Suite>
<Test>
<Result_Path>testngreports/system.apps.webdriver.tests.crm.mot.CreateTerritoryProposalTest/initTest</Result_Path>
</Test>
<Test>
<Result_Path>testngreports/system.apps.webdriver.tests.crm.mot.CreateTerritoryProposalTest/ActListsForContactShowsContactRelatedTasksTest</Result_Path>
</Test>
</Suite>
总结:
电流输出:
testngreports/system.apps.webdriver.tests.crm.mot.CreateTerritoryProposalTest/initTest
预期输出:
testngreports/system.apps.webdriver.tests.crm.mot/CreateTerritoryProposalTest/initTest
最后一个'.'字符应替换为'/'
【问题讨论】: