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&a mp;gt;
<weight units="kg">75</weight&am p;gt;
</person>
<person id="2" name="Tom Stone">
<age>26</age>
<height units="cm">177</height&a mp;gt;
<weight units="kg">65</weight&am p;gt;
</person>
</person_list>
FUNCT ION.XSL
----------
Try this function which would take two parameter as in input.
<xsl:stylesheet version="2.0"
xmlns:xsl="h ttp://www.w3.org/1999/XSL/Transform& quot;
xmlns:my="http://www.mysite.co m/my&quot;>
<xsl:function name="my:age">
<xslaram name="ageRequired"/>
<xsl aram name="ageCurrent"/>
<xsl: if test="$ageCurrent > $ageRequired">
The current age is <xsl:value-of select="$ageCurrent"/>
</ xsl:if>
</xsl:function>
<xsl:t emplate match="/">
<xsl:for-each select="person_list/person"&am p;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