Created
September 25, 2017 09:25
-
-
Save thieux/76913bd16f57d1018f040a5efdc9afce to your computer and use it in GitHub Desktop.
Unit test in XSLT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<root> | |
<name username="JS1">John</name> | |
<name username="MI1">Morka</name> | |
</root> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" indent="yes"/> | |
<xsl:template match="/persons"> | |
<root> | |
<xsl:apply-templates select="persons"/> | |
</root> | |
</xsl:template> | |
<xsl:template match="person"> | |
<name username="{@username}"> | |
<xsl:value-of select="name" /> | |
</name> | |
</xsl:template> | |
</xsl:stylesheet> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" ?> | |
<persons> | |
<person username="JS1"> | |
<name>John</name> | |
<family-name>Smith</family-name> | |
</person> | |
<person username="MI1"> | |
<name>Morka</name> | |
<family-name>Ismincius</family-name> | |
</person> | |
</persons> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
xsltproc extract-username.xslt persons.xml > /tmp/actual-username.xml | |
e=`openssl sha1 expected-username.xml | awk '{ print $2; }'` | |
a=`openssl sha1 /tmp/actual-username.xml | awk '{ print $2; }'` | |
if [[ "$a" == "$e" ]]; then | |
echo "pass" | |
else | |
echo "FAILURE" | |
vimdiff /tmp/actual-username.xml expected-username.xml | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment