473,471 Members | 2,040 Online
Bytes | Software Development & Data Engineering Community
Create 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 1385
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
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...
4
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...
1
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...
3
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...
0
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....
18
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...
6
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...
1
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...
6
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.