xslt将节点值复制到其他节点变量
我正试图编写一个xslt样式表,使standar junit报告通过jenkins可读。 我有这个报告文件:xslt将节点值复制到其他节点变量,xslt,Xslt,我正试图编写一个xslt样式表,使standar junit报告通过jenkins可读。 我有这个报告文件: <?xml version="1.0" encoding="UTF-8"?> <testsuites name="Test.postman.OpenWeather.01" tests="2" time="0.368"> <testsuite name="getRandomCityById" id="a3fd8f91-a116-434b-9717-d40d
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Test.postman.OpenWeather.01" tests="2" time="0.368">
<testsuite name="getRandomCityById" id="a3fd8f91-a116-434b-9717-d40d61a03b59" timestamp="2019-02-06T11:28:55.732Z" classname="getRandomCityById" tests="1" failures="0" errors="0" time="0.252">
<testcase name="Status code is 200" time="0.252"/>
</testsuite>
<testsuite name="getCityByName" id="4b65811e-9f86-48fb-904d-6eb9c8094b68" timestamp="2019-02-06T11:28:55.732Z" classname="getCityByName" tests="3" failures="0" errors="0" time="0.116">
<testcase name="City Name matches Request'" time="0.116"/>
<testcase name="Contains object: 'weather'" time="0.116"/>
<testcase name="DOES NOT Contain string: 'snow' " time="0.116"/>
</testsuite>
</testsuites>
但我的输出必须是:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Test.postman.OpenWeather.01" tests="2" time="0.368">
<testsuite name="getRandomCityById" id="a3fd8f91-a116-434b-9717-d40d61a03b59" timestamp="2019-02-06T11:28:55.732Z" classname="Test.postman.OpenWeather.01" tests="1" failures="0" errors="0" time="0.252">
<testcase name="Status code is 200" time="0.252"/>
</testsuite>
<testsuite name="getCityByName" id="4b65811e-9f86-48fb-904d-6eb9c8094b68" timestamp="2019-02-06T11:28:55.732Z" classname="Test.postman.OpenWeather.01" tests="3" failures="0" errors="0" time="0.116">
<testcase name="City Name matches Request'" time="0.116"/>
<testcase name="Contains object: 'weather'" time="0.116"/>
<testcase name="DOES NOT Contain string: 'snow' " time="0.116"/>
</testsuite>
</testsuites>
在所有testsuite类名中,我需要testsuite名称Test.postman.OpenWeather.01
我不会写xslt,有人能帮我吗?
提前感谢如果给定的XML是您的输入文件,那么可以在XSLT 1.0中实现以下结果:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="testsuite">
<xsl:copy>
<xsl:attribute name="classname">
<xsl:value-of select="ancestor::node()/@name" />
</xsl:attribute>
<xsl:for-each select="@*">
<xsl:if test="name() != 'classname'">
<xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>
</xsl:if>
</xsl:for-each>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>