473,545 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT Newbie Questions

3 New Member
Couple of newbie questions and one specific to the issue I am trying to solve.

In some cases, my XSLT will specify <xsl:output method="xml"/> but the output will be plain text with no XML tags or delimiters.

Second, I'm having some issues understanding templates. The basic format seems straightforward enough when I look at examples. However, I run into some issues trying to understand when the templates are evaluated, when to use an "apply-templates" after a match, and when to use a match vs. select.

Finally my specific issue.

My input XML may look something like this:
<ServiceTags>
<Service parm="123455">
<name>Joe Blow</name>
<address>1234 Oak Street</address>
</Service>
<Service parm="98989">
<name>Tom Swift</name>
<address>1721 3rd Street</address>
</Service>
<Service parm="123455">
<city>detroit </city>
<state>mi</state>
<Service parm="98989">
<city>san diego</city>
<state>ca</state>
</ServiceTags>

Note that the parm values are the same for a couple of elements, but the child elements are different. What I'm trying to do is to be able to treat the two sets of child elements as one. Any thoughts on this?

Thanks.
Jan 23 '08 #1
4 1391
jkmyoung
2,057 Recognized Expert Top Contributor
Muenchian Grouping is one technique of grouping similar nodes together. (XSLT 1.0)
XSLT 2.0 has built-in functions for the grouping of nodes.

Muenchian grouping is like so:
Expand|Select|Wrap|Line Numbers
  1. <xsl:key name="ServiceByParm" match="Service" use="@parm"/>
  2.  
  3. <xsl:for-each select="//Service[count(.|(key('ServiceByParm', @parm)[1])=1]">
  4.    <!--  Node group:-->
  5.   <xsl:for-each select="key('ServiceByParm', @parm)">
  6.       <!-- All nodes in this group -->
  7.   </xsl:for-each>
  8. </xsl:for-each>
  9.  
Yeah, the logic of templates is a little bit complicated, since it's not like most linear progams that people are used to.

The output is not really affected by the method in most cases.
Jan 24 '08 #2
charlesw7
3 New Member
Thanks for your reply. I decided last night to stop messing around and read the XSLT spec from W3C and that helped clear things up somewhat. I had also run across the Muenchian grouping solution, which is helping me solve the problem. So I appreciate you adding the code specific to my example.

As for the template processing thing, I'll probably still struggle with it for awhile, but should catch on soon enough.

Thanks again for answering a stupid question.
Jan 24 '08 #3
charlesw7
3 New Member
Late Friday afternoon is probably not the best time to post this, but...
In any case, the code that was posted here has been a great help. However, I think there are still some things I'm missing.

One thing I neglected in my original example here was how I need to grab pieces of data from each node once the data is 'grouped'.

A better representation of this data is like:
<ServiceTags>
<Service parm="123455">
<name>Joe Blow</name>
<address>1234 Oak Street</address>
<name>Sam Blow</name>
<address>123 Elm Street</address>
<name>Eli Blow</name>
<address>998 7th ave</address>
</Service>
<Service parm="98981">
<name>Tom Brady</name>
<address>1721 3rd Street</address>
<name>Tom Sawyer</name>
<address>9191 old oak way</address>
<name>Tom Greenbaum</name>
<address>42 blue ribbon drive</address>
</Service>
<Service parm="123455">
<city>detroit </city>
<state>mi</state>
</Service>
<Service parm="98989">
<city>san diego</city>
<state>ca</state>
</Service>
</ServiceTags>

Notice that the <Service> elements which include the <name> and <address> elements may repeat within the <Service> element.

The problem should be simple to solve, but I'm stuck. I am trying to tie the names and addresses to the city and states where the parm values match between <Service> elements, and output something a little more reasonable - something that might look more like for each set.
<Service parm="98981">
<name></name>
<address></address>
<city></city>
<state></state>
</Service>

etc.

Point is I think I have figured out how things get grouped and sorted, but am having trouble accessing the correct node once I've done that.

Thanks.
Jan 25 '08 #4
jkmyoung
2,057 Recognized Expert Top Contributor
Problem is the name is not 'really' grouped to the address.
You'll probably have to use an axis:

Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="name">
  2. ...
  3. <xsl:value-of select="following-sibling::address[1]"/>
  4. ...
  5. </xsl:for-each>
  6.  
Note: the [1] limits the address node only to the one directly following the name.

http://www.zvon.org/xxl/XSLTreferenc...axesIndex.html
Jan 28 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1907
by: mali djuro | last post by:
Hi, all! i am newbie in all this stuffs about xsl, so i have few questions for you, Please, can you tell me is this possible to do, and if you can please give me some guide lines. here is problem or whatever: i got a following xml file:
4
1219
by: Trygve | last post by:
I'm trying to convert a XML-document using XSLT. Depending on the source file (the XML-document) the conversion is either correct or incorrect. If the first tag in the document contains an non empty xmlns attribute: <Meldekorttype xmlns="http://myhost.com/mk_print_meldekort.xsd"> <tag1>Value1</tag1> <tag2>Value2</tag2> </Meldekorttype>
1
1420
by: Mark | last post by:
I must say that I'm quite the newb with XML/XSLT. I kind of stubmled upon using it for a report I'm trying to make. If someone would be so kind as to help out with the following I would be grateful. I have the following XML output from SQL server 2000 and would like to transform it such that teh questions are grouped by QID....
3
2240
by: Jack Fox | last post by:
I've never had the need to work with XML, but I believe I now have an appropriate application. I have time-series data in objects organized as a tree that I want an ASP.NET program to write out to web pages formatted as a matrix. It is not a simple matrix, since the number of row heading cells can vary, but the data cells must be aligned by...
0
3285
by: DAnne | last post by:
Hi, I'm very new to xslt and this is my first time posting to a Forum so please forgive me if I transgress any protocols. I have to do a tally report. This report is divided up into sections. Each section has a list of questions. Each question has responses. I need to display a list of responses to the questions (i.e. set:distinct), once...
18
2052
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to look up what each feature depends on and gerenate a text file. For example, in the following file, I would like to find out feature A depends on A1...
6
1639
Gaiason
by: Gaiason | last post by:
Hi XML/XSLT masters and gurus, I am a newbie in XML/XSLT and have been reading up XML/XSLT in order to convert a XML generated from a OCR engine to another format of XML. I am truly stuck at this stage that I really need expert help on what is the thing that I might be missing or not understand. Basically, my desired output is to get the...
1
3794
by: qbp90x5lb | last post by:
I'm using an XSLT transform to output the element value contents from a simple XML file into a new .TXT file. Everything works fine except for certain XML files, when calling msxsl with the .xslt, I get the following error: Code: 0xc00ce504 File: ...... Line: ... Column: ... A name was started with an invalid character. The...
6
3717
by: John Larson | last post by:
Hi All, I am some information from INSPEC database records in XML to build a relational database of my own. I am currently trying to extract information by doing an XSLT transform of the XML files into a tab-separated text file that I want to import into the database. I have run into the following problem: in some documents there are...
0
7496
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
7428
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
7452
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
7784
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
6014
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
5354
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...
0
3485
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
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 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.