Skip to content

Commit

Permalink
xalan:strings
Browse files Browse the repository at this point in the history
  • Loading branch information
lindenb committed May 21, 2016
1 parent a39de42 commit 97bb237
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
17 changes: 17 additions & 0 deletions xalan/src/main/java/com/github/lindenb/xslt/strings/Strings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.lindenb.xslt.strings;

import org.apache.xalan.extensions.ExpressionContext;


import com.github.lindenb.xslt.AbstractXalanExtension;

public class Strings extends AbstractXalanExtension
{
public Object strcmp(final ExpressionContext context,final String s1,final String s2)
{
if(s1==null && s2==null) return 0;
if(s1==null && s2!=null) return -1;
if(s1!=null && s2==null) return 1;
return s1.compareTo(s2);
}
}
4 changes: 4 additions & 0 deletions xalan/src/test/resources/test02.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<a>
<c><s1>ATAGXGACT</s1><s2>ZAADGATGD</s2></c>
<c><s1>ZAADGATGD</s1><s2>ATAGXGACT</s2></c>
</a>
43 changes: 43 additions & 0 deletions xalan/src/test/resources/test02.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version='1.0' encoding="UTF-8" ?>
<xsl:stylesheet
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version='1.0'
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:str="xalan://com.github.lindenb.xslt.strings.Strings"
exclude-result-prefixes="xalan str"
>
<xsl:output method="text" />

<xsl:template match="/">
<xsl:for-each select="//c">

<xsl:choose>
<xsl:when test="str:strcmp(s1,s2) &lt; 0">
xalan:<xsl:value-of select="s1"/> &lt; <xsl:value-of select="s2"/>;
</xsl:when>
<xsl:when test="str:strcmp(s1,s2) &gt; 0">
xalan:<xsl:value-of select="s2"/> &lt; <xsl:value-of select="s1"/>;
</xsl:when>
<xsl:otherwise>
xalan:ERROR;
</xsl:otherwise>
</xsl:choose>


<xsl:choose>
<xsl:when test="s1/text() &lt; s2/text()">
native:<xsl:value-of select="s1"/> &lt; <xsl:value-of select="s2"/>;
</xsl:when>
<xsl:when test="s2/text() &lt; s1/text()">
native:<xsl:value-of select="s2"/> &lt; <xsl:value-of select="s1"/>;
</xsl:when>
<xsl:otherwise>
native:ERROR;
</xsl:otherwise>
</xsl:choose>


</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 97bb237

Please sign in to comment.