XSLT Function
I want to implement a custom XSLT function to filter a list of people on the basis of age.
INPUT.XML----------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE person_list SYSTEM "validator.dtd">
<person_list>
<person id="1" name="John Smith">
<age>35</age>
<height units="cm">173</height&gt;
<weight units="kg">75</weight&gt;
</person>
<person id="2" name="Tom Stone">
<age>26</age>
<height units="cm">177</height&gt;
<weight units="kg">65</weight&gt;
</person>
</person_list>
FUNCTION.XSL
----------
Try this function which would take two parameter as in input.
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ;
xmlns:my="http://www.mysite.com/my& ;quot;>
<xsl:function name="my:age">
<xslaram name="ageRequired"/>
<xslaram name="ageCurrent"/>
<xsl:if test="$ageCurrent > $ageRequired">
The current age is <xsl:value-of select="$ageCurrent"/>
</xsl:if>
</xsl:function>
<xsl:template match="/">
<xsl:for-each select="person_list/person"&gt;
<xsl:value-of select="my:age(18, age)"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
INPUT.XML----------
<?xml version="1.0" encoding="ISO-8859-1"?>
<
<person_
<person id="1" name="John Smith">
<age>35</age>
<height units="cm">173</height&a
<weight units="kg">75</weight&am
</person>
<person id="2" name="Tom Stone">
<age>26</age>
<height units="cm">177</height&a
<weight units="kg">65</weight&am
</person>
</person_list>
FUNCT
----------
Try this function which would take two parameter as in input.
<xsl:stylesheet version="2.0"
xmlns:xsl="h
xmlns:my="http://www.mysite.co
<xsl:function name="my:age">
<xslaram name="ageRequired"/>
<xsl
<xsl:
The current age is <xsl:value-of select="$ageCurrent"/>
</
</xsl:function>
<xsl:t
<xsl:for-each select="person_list/person"&am
<xsl:value-of select="my:age(18, age)"/>
</xsl:for-each>
<
</xsl:stylesheet>
No comments:
Post a Comment