 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 21st, 2008, 12:37 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
XSL1.0: extension Function
I am new to XSL xalan extension functon,Find the below requirement of XSL function and the Pseudo-code. could any one help how to call the function in XSL. Also find the xml file,
[u]Function</u>: createAccesFeesGroupList
"Create an AccessFeesGroupList element that contains groups of access charges per tm, sp, sn, price, tax
Each group contains the list of periods to display with the associated amounts.
The returned element has the following structure
<AccessFeesGroupList>
AccessFeesGroup groupType='<>' tm='<>' sp='<>' sn='<>' date='<>' rate='<>' discountValue='<>' invoiceLineValue='<>' vatRate='<>' vatValue='<>' >
<Period dateFrom='<>' dateTo='<>' discountValue='<>' invoiceLineValue='<>' vatValue='<>' />
<Period dateFrom='<>' dateTo='<>' discountValue='<>' invoiceLineValue='<>' vatValue='<>' />
...
</AccessFeesGroup>
...
</AccessFeesGroupList>
"
I just planned to implement the xsl such as
<xsl:variable name="VariantA" select="Invoice/InvoiceItem[@CT='A']"/>
<xsl:template match="/">
<xsl:for-each select="xalan:nodeset($VariantA)//*">
<xsl:value-of select="name(.)"/><xsl:text>,</xsl:text>
</xsl:for-each>
</xsl:template>
|
|

July 22nd, 2008, 12:01 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hope you had seen the algorithm from my previous post... I tried as follows,It's not completed just structure... Please confirm whether i am handling the xalan extension function properly...?
As i mentioned in my previous post, i wnat to create the tree structure and i need to traverse it, as follows,
<AccessFeesGroupList>
<AccessFeesGroup groupType='<>' tm='<>' sp='<>' sn='<>' date='<>' rate='<>' discountValue='<>' invoiceLineValue='<>' vatRate='<>' vatValue='<>' >
<Period dateFrom='<>' dateTo='<>' discountValue='<>' invoiceLineValue='<>' vatValue='<>' />
<Period dateFrom='<>' dateTo='<>' discountValue='<>' invoiceLineValue='<>' vatValue='<>' />
...
</AccessFeesGroup>
...
</AccessFeesGroupList>
[u]My Sample Code:</u>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan"
version="1.0">
<xsl:output method="text"/>
<xsl:key name="by-id" match="Att[@Ty='TM']" use="@Id"/>
<xsl:variable name="VariantA">
<xsl:for-each select="Invoice/InvoiceItem[@CT='A']">
<AccessFeesGroupList>
<xsl:call-template name="createAccessFeesPeriods"/>
</AccessFeesGroupList>
</xsl:for-each>
</xsl:variable>
<xsl:template match="/">
<xsl:for-each select="xalan:nodeset($VariantA)/AccessFeesGroupList">
</xsl:for-each>
</xsl:template>
<xsl:template name="createAccessFeesPeriods">
<xsl:for-each select="Invoice/InvoiceItem/AggSet/Att[@Ty='TM'][generate-id() = generate-id(key('by-id', @Id)[1])]">
<AccessFeesGroup>
<xsl:value-of select="../../../Date[@Type='START']/@Date"/>
</AccessFeesGroup>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
|
|

July 22nd, 2008, 03:27 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
xalan:nodeset does not convert 'text' into a nodeset, but an XML fragment into a nodeset.
In you above example you are creating your <AccessFeesGroup> element by using < and > - this is wrong. Just use <AccessFeesGroup> and </AccessFeesGroup>
If you 'think' the above is wrong then I can only assume its not working - if it isn't working then you don't say why or what errors you are getting?
/- Sam Judson : Wrox Technical Editor -/
|
|

July 22nd, 2008, 07:51 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes your right!
Here with i have replied with detailed of my requirement.
1) Need to implement the functions using xalan extension.
2) An important point for implementing these functions is that they use xml constructs(Any idea on this xml constructs ?).
3) As these are normaly target tree parts, they should be converted to input source tree at some stage : i.e. inpout source can be queried but not modified, and conversly target tree can be written but not read.
To convert from target tree part to source tree, you need to use an extension function : one is available with xalan => nodeset (see http://xml.apache.org/xalan-c/extens...b.html#nodeset
Question: Any idea about(3), any related examples available ?
|
|

July 22nd, 2008, 08:50 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
The link you supply above has an example of how to use the xalan:nodeset function in it - and you are using it in the code above. So I don't see your problem.
Again, you are asking us to tell you why code does not work without telling us what it is doing wrong.
/- Sam Judson : Wrox Technical Editor -/
|
|

July 23rd, 2008, 01:41 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your reply.
- I have multiple input xml files.
- Converting the xml file into ASCII file with defined format.
- At some stage its not possible to add own xml in the source input xml file( please skip this, it has more detail)
- so i planned to use xalan extension function, as i specified in the post such as
<xsl:variable name="VariantA">
<AccessFeesGroupList>
<AccessFeesGroup gropu=""><Period date="20080202"/></AccessFeesGroup>
<AccessFeesGroup gropu="">..</AccessFeesGroup>
....
</AccessFeesGroupList>
</xsl:variable>
[u]Question 1:</u>
I am unable to acces the AccessFeesGroup such as,
<xsl:template match="/">
<xsl:for-each select="xalan:nodeset($VariantA)/AccessFeesGroupList/AccessFeesGroup ">
<xsl:value-of select="Period/@date"/>
</xsl:for-each>
</xsl:template>
[u]Expected output:</u> 20080202
[u]Question2:</u>
Inside the variable its a legal to call the template such as
<xsl:variable name="VariantA">
<AccessFeesGroupList><Period dateFrom='20080202' dateTo='' discountValue='' invoiceLineValue='' vatValue='' />
<xsl:call-template name="createAccessFeesPeriods"/>
</AccessFeesGroupList>
</xsl:variable>
|
|

July 23rd, 2008, 02:01 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
We're getting closer. But instead of saying "I am unable to access", tell us what happened. An error message? No output?
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
|
|

July 23rd, 2008, 02:05 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry for my bad explanation.
====> No output. No error message.
[u]Find the complete xsl file as follows,</u>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" version="1.0">
<xsl:output method="text"/>
<xsl:key name="by-id" match="Att[@Ty='TM']" use="@Id"/>
<xsl:variable name="VariantA">
<AccessFeesGroupList>
<xsl:call-template name="createAccessFeesPeriods"/>
</AccessFeesGroupList>
</xsl:variable>
<xsl:template match="/">
<xsl:for-each select="xalan:nodeset($VariantA)/AccessFeesGroupList/AccessFeesGroup">
<xsl:value-of select="Period/@dateFrom"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="createAccessFeesPeriods">
<xsl:for-each select="Document/Invoice/InvoiceItem/AggSet/Att[@Ty='TM'][generate-id() = generate-id(key('by-id', @Id)[1])]">
<AccessFeesGroup>
<Period dateFrom='20080202' dateTo='' discountValue='' invoiceLineValue='' vatValue=''/>
</AccessFeesGroup>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
[u]Result:</u> No output. No error message.
|
|

July 23rd, 2008, 03:30 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
The following work fine for me in the latest version of Xalan:
<xsl:variable name="VariantA">
<AccessGroupList>
<AccessGroup><Period date="12345678"/></AccessGroup>
</AccessGroupList>
</xsl:variable>
<xsl:template match="/">
<xsl:for-each select="xalan:nodeset($VariantA)/AccessGroupList/AccessGroup">
<xsl:value-of select="Period/@date"/>
</xsl:for-each>
</xsl:template>
Therefore if you are not getting an error, but are getting no output then it must be something to do with your input document, which you haven't shown us. The template "createAccessFeesPeriods" obviously isn't returning any elements.
/- Sam Judson : Wrox Technical Editor -/
|
|

July 23rd, 2008, 03:44 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes your right. The above code will work fine,
but if u change to the following, it will not work?
<xsl:variable name="VariantA">
<AccessFeesGroupList>
<xsl:call-template name="createAccessFeesPeriods"/>
</AccessFeesGroupList>
</xsl:variable>
<xsl:template name="createAccessFeesPeriods">
<xsl:for-each select="Document/Invoice/InvoiceItem/AggSet/Att[@Ty='TM'][generate-id() = generate-id(key('by-id', @Id)[1])]">
<AccessFeesGroup>
<Period dateFrom='20080202' dateTo='' discountValue='' invoiceLineValue='' vatValue=''/>
</AccessFeesGroup>
</xsl:for-each>
</xsl:template>
|
|
 |