XSLT Custom filter function
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Sat Mar 27, 2010 3:19 am
XSLT Custom filter function
Hello,
I need some help here, please.
I want to implement a custom XSLT function to filter a list of people. It is supposed to make a simple comparison and output the ones matching the filter but it is not working properly.
Thanks in advance!
Here are my files:
----------
person.xml
----------
----------
person.xsl
----------
I need some help here, please.
I want to implement a custom XSLT function to filter a list of people. It is supposed to make a simple comparison and output the ones matching the filter but it is not working properly.
Thanks in advance!
Here are my files:
----------
person.xml
----------
Code: Select all
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="person.xsl"?>
<!DOCTYPE person_list SYSTEM "validator.dtd">
<person_list>
<person id="1" name="John Smith">
<age>35</age>
<height units="cm">173</height>
<weight units="kg">75</weight>
</person>
<person id="2" name="Tom Stone">
<age>26</age>
<height units="cm">177</height>
<weight units="kg">65</weight>
</person>
<person id="3" name="Mark Glennford">
<age>17</age>
<height units="cm">181</height>
<weight units="kg">61</weight>
</person>
</person_list>
person.xsl
----------
Code: Select all
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="http://www.mysite.com/my">
<xsl:function name="my:age">
<xsl:param name="age"/>
<xsl:for-each select="person_list/person">
<xsl:if test="age > $age">
<!-- code to display data: age, height, weight-->
</xsl:if>
</xsl:for-each>
</xsl:function>
<xsl:template match="/">
<xsl:value-of select="my:age(18)"/><!-- isn't it supposed to output the data for person with ids "1" and "2"? -->
</xsl:template>
</xsl:stylesheet>
-
- Posts: 2883
- Joined: Tue May 17, 2005 4:01 pm
Re: XSLT Custom filter function
Hello,
You could use a template instead of a function so you would also have the context:
Regards,
Adrian
You could use a template instead of a function so you would also have the context:
Code: Select all
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="http://www.mysite.com/my">
<xsl:template name="my:age">
<xsl:param name="age"/>
<xsl:for-each select="person_list/person">
<xsl:if test="age > $age">
<!-- code to display data: age, height, weight-->
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="/">
<xsl:call-template name="my:age">
<xsl:with-param name="age">18</xsl:with-param>
</xsl:call-template>
<!-- isn't it supposed to output the data for person with ids "1" and "2"? -->
</xsl:template>
</xsl:stylesheet>
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service