I don't know how to group the following data in the way I want it. I want
the output of the transformation to be "5678". Does anyone know what I am
doing worry?
<?xml version="1.0"?>
<data>
<unit sn="5">
<test-a>
<result id="0">5</result>
</test-a>
<test-a>
<result id="1">6</result>
</test-a>
<test-b>
<result id="0">10</result>
</test-b>
</unit>
<unit sn="6">
<test-a>
<result id="1">8</result>
</test-a>
<test-a>
<result id="0">7</result>
</test-a>
<test-b>
<result id="0">11</result>
</test-b>
</unit>
</data>
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="ur n:schemas-microsoft-com:xslt">
<xsl:output method="text" />
<xsl:template match="unit[1]">
<xsl:apply-templates select="test-a" />
</xsl:template>
<xsl:template match="unit">
<xsl:variable name="my-sort">
<xsl:for-each select="/data/unit[1]/test-a/result">
<xsl:value-of select="@id" />
</xsl:for-each>
</xsl:variable>
<xsl:apply-templates select="test-a">
<xsl:sort
select="count(m sxsl:node-set($my-sort)/*[string()=string (current()/result/@id)]/preceding-sibling::*)"
data-type="number" />
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet> 5 1604
I don't know how to group the following data in the way I want it. I want
the output of the transformation to be "5678". Does anyone know what I am
doing worry?
I couldn't guess what grouping you were trying to do from your required
output, so I can't suggest what xslt you need. You may want to look at http://www.jenitennison.com/xslt/grouping
However I can point out some errors in your code
<xsl:variable name="my-sort">
<xsl:for-each select="/data/unit[1]/test-a/result">
<xsl:value-of select="@id" />
</xsl:for-each>
This result tree fragment variable just consists of a single root node
(/) with child a text node with value which is the concatenation of all
the selected id attribute values. There are no elements.
so when you make this into a node set
msxsl:node-set($my-sort)
You get a single root node equivalent to the root node of a document
with no elements so msxsl:node-set($my-sort)/* will always be the empty
node set.
David
> I couldn't guess what grouping you were trying to do from your required output, so I can't suggest what xslt you need. You may want to look at http://www.jenitennison.com/xslt/grouping However I can point out some errors in your code
<xsl:variable name="my-sort"> <xsl:for-each select="/data/unit[1]/test-a/result"> <xsl:value-of select="@id" /> </xsl:for-each>
This result tree fragment variable just consists of a single root node (/) with child a text node with value which is the concatenation of all the selected id attribute values. There are no elements.
so when you make this into a node set
msxsl:node-set($my-sort)
You get a single root node equivalent to the root node of a document with no elements so msxsl:node-set($my-sort)/* will always be the empty node set.
David
The problem I am having is the test-a elements are unsorted between unit
elements. I don't care how the test-a elements are sorted as long as they
are sorted the same way. So what I have tried to do is repeat the order of
the first unit's test-a elements. I know the first unit will always be at
/data/unit[1] so that's why I did that. The test-a element always has one
result element, so I don't have to worry about concatenation. I was hoping
$my-sort would contain a sequence of text nodes, which would allow me to
order following test-a elements based on the first unit's test-a elements.
"Mike King" <em*****@excite .com> writes:
... The test-a element always has one result element, so I don't have to worry about concatenation.
But you selected more than one such element and concatenated the result.
you get the concatenation of all the id values of result elements below
the first unit, so "01" in your sample input.
I was hoping $my-sort would contain a sequence of text nodes, which would allow me to order following test-a elements based on the first unit's test-a elements.
It contains a root node with child a single text node, but even if it
did contain a sequence of text nodes (which is never possible in XPath
1, adjacent text nodes that share a parent atre always merged)
your Xpath of
msxsl:node-set($my-sort)/*[....
would select nothing as msxsl:node-set($my-sort)/* selects al the element
children (and text nodes are not elements).
I think that for each unit you just want to iterate through the first
one and select children with ids in that order. You don't need
xx:node-set for that:
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
<xsl:output method="text" />
<xsl:variable name="order" select="data/unit[1]/test-a/result"/>
<xsl:template match="unit">
unit [<xsl:value-of select="@sn"/>]
<xsl:variable name="u" select="."/>
<xsl:for-each select="$order/@id">
<xsl:apply-templates select="$u/test-a/result[@id=current()]"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
produces
unit [5]
56
unit [6]
78
on your sample input.
David
The following XSLT works for my test case but I don't know why. I would
think the value of the keys needs to be the position of the test-a element
for this to work. How can I assign the position to the keys?
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:key name="my-testa-order" match="/data/unit[1]/test-a/result/@id"
use="current()" />
<xsl:template match="unit">
<xsl:apply-templates select="test-a">
<xsl:sort select="key('my-testa-order', result/@id)"
data-type="number" />
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
"Mike King" <em*****@excite .com> writes: The following XSLT works for my test case but I don't know why.
It works becaus eon your test file the results in teh first unit have
unique values, that are in the same order as the id's so your sort
values are 5 and 6 (the values of the results). If for example the
values in the first unit had been equal then everything would get that
sort value and no sorting woul happen.
I would think the value of the keys needs to be the position of the test-a element for this to work. How can I assign the position to the keys?
You can't: keys always return nodes not arbitrary values (such as integer
positions)
You could use a sort of
<xsl:sort select="count(k ey('my-testa-order', result/@id)/../../preceding-sibling::test-a)"
but see previous reply
David <?xml version="1.0"?> <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" /> <xsl:key name="my-testa-order" match="/data/unit[1]/test-a/result/@id" use="current()" />
<xsl:template match="unit"> <xsl:apply-templates select="test-a"> <xsl:sort select="key('my-testa-order', result/@id)" data-type="number" /> </xsl:apply-templates> </xsl:template> </xsl:stylesheet> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Debbie Davis |
last post by:
Hi there,
SQL 2000
I have the following query:
SELECT sponsor, COUNT(sponsor) * 2 AS total FROM Referrals
GROUP BY sponsor
Works great, returns the sponsor and the total * 2 of their referrals
|
by: Jody Greening |
last post by:
Transforming with XSLT, Grouping elements until difference found.
I am seeking some help with the following problem, I am fairly new at
XSLT transformations, and my problem may lie in looking at it from a
traditional programming point of view.
I have did quite a bit of searching but have found no answers to my
particular problem... please read below XML for the problem I am
having.
|
by: Andreas Håkansson |
last post by:
Seeing how my previous post seem to have fallen between the
cracks, I thought I would have a second, more direct, go at it.
So my question is "Is it possible to group (Muenchian method)
over multiple nodes?" I will use an example to try to explain what
I need to do and what I have for data. The example might not be
very realistic but it's much easier than to try and explain using the
scenario I have =P
Suppose I had a list of...
|
by: Brian Coy |
last post by:
I am creating a database to track scrap on a daily basis at my plant.
I have to provide a weekly scrap report with the amount of each part
scrapped per day. I have the basic database set up, and am trying to
generate a report. I have created a report that will show all the
data. But I need to show either an empty group for the data on days
that there is no scrap or a comment relating as much.
My report is set up with a weekly...
|
by: ahaque38 |
last post by:
Hello.
Using A2K SP3, I am having the following problem with a report using
"Sorting and Grouping".
I have recently added a grouping in the reports for
"Category2<>'CONTRACTS'".
I have reports at the plan (overall totals), department and division
levels which have sorting and grouping implemented with this new
| |
by: Mike MacSween |
last post by:
tblCourses one to many to tblEvents.
A course may have an intro workshop (a type of event), a mid course
workshop, a final exam. Or any combination. Or something different in the
future.
At the moment the printed output is usually going to Word. It's turning into
an unholy mess, because I'm having to prepare umpteen different Word
templates, and the queries that drive them, depending on what events a
course has.
|
by: virendra |
last post by:
hi,
I am working on crystal report 9 in asp.net. I created multilevel
dynamic grouping in CR.
if page is load firsttime. and i am giving firstlevel of grouping or
whatever it's working fine.
but once page is loaded and i am changing the grouping options it's not
affecting the page. whatever the previous data in report that only is
showing. but it's exporting properly in excel file. So it can be a
problem of cache.
|
by: Corey |
last post by:
hello,
I’m trying to run a query and I’m getting error messages
Can anyone help me get though this problem?
1: Tried this and got this error message
ORA-00923
, decode (grouping(dsd.Field1,'RETURNED', COUNT(*), 0)) Net1
, decode (grouping(dsd.field1,'COMPLETED', COUNT(*), 0)) Net2
|
by: Chris |
last post by:
I tried to retrieve the digit grouping symbol in MSAccess but
unfortunately 3;0 is retrieved instead of comma which is my symbol.
Function retrieves decimal symbol and list separator without any
problem.
I used the code below:
var_char_copied = GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SGROUPING, var_SYSTEM_DTG, Len(var_SYSTEM_DTG))
|
by: patjones |
last post by:
Good afternoon:
This seems like it shouldn't be hard, and then again this is how so many problems seem at the outset. My situation is this:
I have a report called rptMain319, which is based on a table tblMain319. The report groups employees by their work location (). By putting a Count(*) function in the footer for the Payroll Distribution grouping, I can get the total number of employees in that particular work location.
My problem...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
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
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |