2

I have the below XSLT file and I just want to run it through SHELL script.

 <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="test-method[@status = 'FAIL']"/>
</xsl:stylesheet>

Sample XML:

<?xml version="1.0" encoding="UTF-8"?>
<test-result>
    <test-method status="PASS" name="beforeTestSetup" is-config="true" duration-ms="705" started-at="2018-08-16T21:39:59Z" finished-at="2018-08-16T21:39:59Z">
        <params>
            <param index="0">
                <value>
                    <![CDATA[org.testng.TestRunner@31c2affc]]>
                </value>
            </param>
        </params>   
    </test-method>
    <test-method status="FAIL" name="beforeTestSetup" is-config="true" duration-ms="805" started-at="2018-08-16T21:39:59Z" finished-at="2018-08-16T21:39:59Z">
        <params>
            <param index="0">
                <value>
                    <![CDATA[org.testng.TestRunner@31c2affc]]>
                </value>
            </param>
        </params>   
    </test-method>
    <test-method status="PASS" name="TEST" is-config="true" duration-ms="905" started-at="2018-08-16T21:39:59Z" finished-at="2018-08-16T21:39:59Z">
        <params>
            <param index="0">
                <value>
                    <![CDATA[org.testng.TestRunner@31c2affc]]>
                </value>
            </param>
        </params>   
    </test-method>      
</test-result>

I just want to run the above xslt against the sample XML through SHELL script and I want to use it in the JENKINS shell script editor.

Is there any way to achieve this?

2
  • I suppose you'd need to use an xslt processor tool like xsltproc. E.g. xsltproc <xsltfile> <xmlfile> Commented Dec 12, 2018 at 11:59
  • Can you give some example. It will be very helpful to implement. Commented Dec 12, 2018 at 12:03

1 Answer 1

7

You need an XSLT processor to apply an XSLT style file to an XML input file.

We use xsltproc for this and the shell command is

xsltproc [other_options] --output output.xml style.xslt input.xml

See the xsltproc manual page for the other_options. In a nutshell:

SYNOPSIS
       xsltproc [[-V | --version] [-v | --verbose] [{-o | --output} {FILE | DIRECTORY}] |
                --timing | --repeat | --debug | --novalid | --noout | --maxdepth VALUE | --html |
                --encoding ENCODING  | --param PARAMNAME PARAMVALUE  |
                --stringparam PARAMNAME PARAMVALUE  | --nonet | --path "PATH(S)" | --load-trace |
                --catalogs | --xinclude | [--profile | --norman] | --dumpextensions | --nowrite |
                --nomkdir | --writesubtree PATH | --nodtdattr] [STYLESHEET] {XML-FILE | -}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.