473,545 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

accessing previous context inside apply-templates?

Is it possible to access your caller's (not parent) context while
inside a <xsl:template match...> or <xsl:for-each...>? Here is the xml
I'm using:

<report-set>
...<report>
.....<detail-data>
.......<detail-column position="1" dsc="col1" sum_fg="0"/>
.......<detail-column position="2" dsc="col2" sum_fg="1"/>
.......<detail-column position="3" dsc="col3" sum_fg="1"/>
.......<detail-column position="4" dsc="col4" sum_fg="1"/>
.......<detail-column position="5" dsc="col5" sum_fg="1"/>
.....</detail-data>
.....<invoice inv_id="232243" >
.......<break level="1">
.........<break level="2">
...........<bre ak level="3">
.............<d etail>
............... <row>
............... ..<field position="1">Te xt1</field>
............... ..<field position="2">34 </field>
............... ..<field position="3">34 00.00</field>
............... ..<field position="4">0. 00</field>
............... ..<field position="5">34 00.00</field>
............... </row>
............... <row>
............... ..<field position="1">Te xt2</field>
............... ..<field position="2">96 </field>
............... ..<field position="3">96 00</field>
............... ..<field position="4">0. 00</field>
............... ..<field position="5">96 00.00</field>
............... </row>
.............</detail>
...........</break>
...........<bre ak level="3">
.............<d etail>
............... <row>
............... ..<field position="1">Te xt1</field>
............... ..<field position="2">13 </field>
............... ..<field position="3">13 00.00</field>
............... ..<field position="4">-1300.00</field>
............... ..<field position="5">0. 00</field>
............... </row>
............... <row>
............... ..<field position="1">Te xt2</field>
............... ..<field position="2">13 </field>
............... ..<field position="3">26 00</field>
............... ..<field position="4">0. 00</field>
............... ..<field position="5">26 00.00</field>
............... </row>
.............</detail>
...........</break>
.........</break>
.......</break>
.....</invoice>
...</report>
</report-set>

When I am in the <break> context (of which there can be any number), I
want to output a sum of each field based on the <detail-data> from the
top. I've tried to apply-templates on the
/report-set/report/detail-data/detail-column which can give me a
column for each <detail-column>, but I need to sum from the context
where the apply-templates was called. Is this possible? I've hacked a
way by passing my context position and break level and going back to
look for the break i want, but it's inefficient and hard to read, not
to mention ugly.

Does anyone have any ideas? Please tell me there's an easier way!

Mike Partridge..
Jul 20 '05 #1
3 1730

"Mike Partridge" <ha**********@e arthlink.net> wrote in message
news:61******** *************** ***@posting.goo gle.com...
Is it possible to access your caller's (not parent) context while
inside a <xsl:template match...> or <xsl:for-each...>? Here is the xml
I'm using:

<report-set>
..<report>
....<detail-data>
......<detail-column position="1" dsc="col1" sum_fg="0"/>
......<detail-column position="2" dsc="col2" sum_fg="1"/>
......<detail-column position="3" dsc="col3" sum_fg="1"/>
......<detail-column position="4" dsc="col4" sum_fg="1"/>
......<detail-column position="5" dsc="col5" sum_fg="1"/>
....</detail-data>
....<invoice inv_id="232243" >
......<break level="1">
........<break level="2">
..........<brea k level="3">
............<de tail>
..............< row>
............... .<field position="1">Te xt1</field>
............... .<field position="2">34 </field>
............... .<field position="3">34 00.00</field>
............... .<field position="4">0. 00</field>
............... .<field position="5">34 00.00</field>
..............</row>
..............< row>
............... .<field position="1">Te xt2</field>
............... .<field position="2">96 </field>
............... .<field position="3">96 00</field>
............... .<field position="4">0. 00</field>
............... .<field position="5">96 00.00</field>
..............</row>
............</detail>
..........</break>
..........<brea k level="3">
............<de tail>
..............< row>
............... .<field position="1">Te xt1</field>
............... .<field position="2">13 </field>
............... .<field position="3">13 00.00</field>
............... .<field position="4">-1300.00</field>
............... .<field position="5">0. 00</field>
..............</row>
..............< row>
............... .<field position="1">Te xt2</field>
............... .<field position="2">13 </field>
............... .<field position="3">26 00</field>
............... .<field position="4">0. 00</field>
............... .<field position="5">26 00.00</field>
..............</row>
............</detail>
..........</break>
........</break>
......</break>
....</invoice>
..</report>
</report-set>

When I am in the <break> context (of which there can be any number), I
want to output a sum of each field based on the <detail-data> from the
top. I've tried to apply-templates on the
/report-set/report/detail-data/detail-column which can give me a
column for each <detail-column>, but I need to sum from the context
where the apply-templates was called. Is this possible? I've hacked a
way by passing my context position and break level and going back to
look for the break i want, but it's inefficient and hard to read, not
to mention ugly.

Does anyone have any ideas? Please tell me there's an easier way!

Mike Partridge..

I am not sure what you exactly want, but if I guess well, this will answer
your question.

This transformation:

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>

<xsl:key name="kDetail" match="detail-column" use="@position"/>

<xsl:template match="row">
<xsl:value-of select="sum(fie ld[key('kDetail',
count(preceding-sibling::*)+1)/@sum_fg = 1])"/>
<xsl:text>&#xA; </xsl:text>
</xsl:template>
</xsl:stylesheet>

when applied on your source.xml:

<report-set>
<report>
<detail-data>
<detail-column position="1" dsc="col1" sum_fg="0"/>
<detail-column position="2" dsc="col2" sum_fg="1"/>
<detail-column position="3" dsc="col3" sum_fg="1"/>
<detail-column position="4" dsc="col4" sum_fg="1"/>
<detail-column position="5" dsc="col5" sum_fg="1"/>
</detail-data>
<invoice inv_id="232243" >
<break level="1">
<break level="2">
<break level="3">
<detail>
<row>
<field position="1">Te xt1</field>
<field position="2">34 </field>
<field position="3">34 00.00</field>
<field position="4">0. 00</field>
<field position="5">34 00.00</field>
</row>
<row>
<field position="1">Te xt2</field>
<field position="2">96 </field>
<field position="3">96 00</field>
<field position="4">0. 00</field>
<field position="5">96 00.00</field>
</row>
</detail>
</break>
<break level="3">
<detail>
<row>
<field position="1">Te xt1</field>
<field position="2">13 </field>
<field position="3">13 00.00</field>
<field position="4">-1300.00</field>
<field position="5">0. 00</field>
</row>
<row>
<field position="1">Te xt2</field>
<field position="2">13 </field>
<field position="3">26 00</field>
<field position="4">0. 00</field>
<field position="5">26 00.00</field>
</row>
</detail>
</break>
</break>
</break>
</invoice>
</report>
</report-set>

produces this output:

6834
19296
13
5213
In case my guess about the real meaning of your message was unsuccessful,
could you, please, describe it in a correct and unambiguous way?
Dimitre Novatchev.
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
Jul 20 '05 #2
No, you guessed perfectly! Thanks so much for your help, and I'm sorry
that my description was difficult to fathom. I see what you're doing,
but can you clarify something? How is count(preceding-sibling::*)+1
different than position() in this case?
I have limited understanding of how to use axes, so please bear with
me. If there are multiple <report> elements that need different sets
of <detail-column>s in <report-set> (see example xml below), how can I
reference the detail-column data from the current report only? If the
xml structure was static I could back up through parent nodes, but I
don't know how many <break>s there are so I can't hardcode the xpath.
I have a feeling there is a relatively simple way to do this using the
ancestor axis, but I'm not sure how.
If I were to create a key as you defined it for the following example
xml, they would conflict correct? That is why I think using the
ancestor axis is the best way.

<report-set>
<report>
<detail-data>
<detail-column position="1" dsc="col1" sum_fg="0"/>
<detail-column position="2" dsc="col2" sum_fg="1"/>
<detail-column position="3" dsc="col3" sum_fg="1"/>
<detail-column position="4" dsc="col4" sum_fg="1"/>
<detail-column position="5" dsc="col5" sum_fg="1"/>
</detail-data>
<invoice inv_id="232243" >
<break level="1">
<break level="2">
<break level="3">
...
</break>
</break>
</break>
</invoice>
</report>
<report>
<detail-data>
<detail-column position="1" dsc="name" sum_fg="0"/>
<detail-column position="2" dsc="descriptio n" sum_fg="0"/>
<detail-column position="3" dsc="amount" sum_fg="1"/>
</detail-data>
<invoice inv_id="232244" >
<break level="1">
<break level="2">
...
</break>
</break>
</invoice>
</report>
</report-set>

Thanks again for your help!

Mike Partridge

"Dimitre Novatchev" <dn********@yah oo.com> wrote in message news:<bu******* *****@ID-152440.news.uni-berlin.de>...
"Mike Partridge" <ha**********@e arthlink.net> wrote in message
news:61******** *************** ***@posting.goo gle.com... ....

When I am in the <break> context (of which there can be any number), I
want to output a sum of each field based on the <detail-data> from the
top. I've tried to apply-templates on the
/report-set/report/detail-data/detail-column which can give me a
column for each <detail-column>, but I need to sum from the context
where the apply-templates was called. Is this possible? I've hacked a
way by passing my context position and break level and going back to
look for the break i want, but it's inefficient and hard to read, not
to mention ugly.

Does anyone have any ideas? Please tell me there's an easier way!

Mike Partridge..

I am not sure what you exactly want, but if I guess well, this will answer
your question.

This transformation:

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>

<xsl:key name="kDetail" match="detail-column" use="@position"/>

<xsl:template match="row">
<xsl:value-of select="sum(fie ld[key('kDetail',
count(preceding-sibling::*)+1)/@sum_fg = 1])"/>
<xsl:text>&#xA; </xsl:text>
</xsl:template>
</xsl:stylesheet>

when applied on your source.xml:

-- snip --
produces this output:

6834
19296
13
5213
In case my guess about the real meaning of your message was unsuccessful,
could you, please, describe it in a correct and unambiguous way?
Dimitre Novatchev.
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html

Jul 20 '05 #3
"Mike Partridge" <ha**********@e arthlink.net> wrote in message news:61******** *************** ***@posting.goo gle.com...
No, you guessed perfectly! Thanks so much for your help, and I'm sorry
that my description was difficult to fathom. I see what you're doing,
but can you clarify something? How is count(preceding-sibling::*)+1
different than position() in this case?
In this case using either of them will produce the same results.

I wanted somehow to express that there's no need for the "position"
attribute on field elements and even that one can do without a
position() function.

There are other scenarios (e.g. when position is not used within a
location step) , when position() will only return the position of the
current node in the current node-list -- this is *not* the same as
count(preceding-sibling::*)+1 and depends on the way the
xsl:apply-templates or the xsl:for-each were specified.

I have limited understanding of how to use axes, so please bear with
me. If there are multiple <report> elements that need different sets
of <detail-column>s in <report-set> (see example xml below), how can I
reference the detail-column data from the current report only? If the
xml structure was static I could back up through parent nodes, but I
don't know how many <break>s there are so I can't hardcode the xpath.
I have a feeling there is a relatively simple way to do this using the
ancestor axis, but I'm not sure how.
If I were to create a key as you defined it for the following example
xml, they would conflict correct? That is why I think using the
ancestor axis is the best way.


There's no problem -- just use:

ancestor::repor t[1]/detail-data
Dimitre Novatchev.
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4953
by: | last post by:
Is it possible to access the previous page's viewstate directly through the context object after a server.transfer. If so, how? The way i'm doing it is saving all needed items to a structure on the previous page, then accessing its variables. I would like a much more direct way if one exists. thanks
5
14915
by: Derek Cooper | last post by:
I hope you can help me. I posted this in the microsoft sql server newsgroup a few days ago and got no response so I thought I'd try here. If I can provide any clarification I'll be glad to do so. I'm trying to calculate a column based on the value of the previous record. I'm not very experienced with SQL-Server. I'm using the following...
2
2282
by: Steven T. Hatton | last post by:
I find the surprising. If I derive Rectangle from Point, I can access the members of Point inherited by Rectangle _IF_ they are actually members of a Rectangle. If I have a member of type Point in Rectangle, the compiler tells me Point::x is protected. I would have expected Rectangle to see the protected members of any Point. Compiling the...
3
7582
by: Pete Atkins | last post by:
Help!!!!!!!! This may have been posted bfore, but i cannot find it. Have written a db in access 2003, opened in access 2000, saved, re-opened,etc - all was fine. Added some new forms / reports, again saved and reopened - all was working fine.
8
3008
by: nkrisraj | last post by:
Hi, I have a following structure: typedef struct { RateData rdr; int RateID; char RateBalance; } RateInfo;
0
12061
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the likelihood of CRM success from less than 20 percent to 60 percent. WHITEPAPER :
89
5956
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be used." Could anybody tell me why gets() function is dangerous?? Thank you very much. Cuthbert
2
2368
by: Gerhard | last post by:
I have a .net application that I want to run in a DMZ, with the SQL Server and file system behind another firewall. Is there a secure way to get to files from my application, or would it be better to have a reverse proxy server in the DMZ and the webserver behind the second firewall?
15
2033
by: Bob | last post by:
Is there anyway to access the global object from inside a function other than doing a "var _global = this;" before declaring the function? Thanks
8
10805
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList steps successfully with the following code... Control myContainer = (Control)Wizard1.FindControl("SideBarContainer"); DataList mySideBarList =...
0
7487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7446
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7778
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6003
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5349
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.