473,320 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

xslt concatenation

1
Hi All,

I am just picking up xslt and I was wondering if I could get some
pointers. I have an xml body that looks like this:
Expand|Select|Wrap|Line Numbers
  1.    <location>
  2.        <civic-address>
  3.           <country>US</country>
  4.           <A1>New York</A1>
  5.           <A2>King's County</A2>
  6.           <A3>New York</A3>
  7.           <A4>Manhattan</A4>
  8.           <A5>Morningside Heights</A5>
  9.           <A6>Broadway</A6>
  10.           <PRD>N</PRD>
  11.           <POD>SW</POD>
  12.           <STS>Street</STS>
  13.           <HNO>123</HNO>
  14.           <HNS>A</HNS>
  15.           <LMK>Low Library</LMK>
  16.           <LOC>Room 543</LOC>
  17.           <FLR>5</FLR>
  18.           <NAM>Joe's Barbershop</NAM>
  19.           <PC>10027-0401</PC>
  20.        </civic-address>
  21.     </location>
  22.    <location>
  23.        <civic-address>
  24.            ...
  25.        </civic-address>
  26.     </location>
  27.    <location>
  28.        <civic-address>
  29.            ...
  30.        </civic-address>
  31.     </location>
I need to translate this (using xslt) to create a new element called
'street' that has the values of HNO HNS PRD A6 POD STS from one civic-
address. So the output should look like:
Expand|Select|Wrap|Line Numbers
  1.    <location>
  2.        <civic-address>
  3.           <country>US</country>
  4.           <A1>New York</A1>
  5.           <A2>King's County</A2>
  6.           <A3>New York</A3>
  7.           <A4>Manhattan</A4>
  8.           <A5>Morningside Heights</A5>
  9.           <street> 123 A N Broadway SW Street </street>
  10.           <LMK>Low Library</LMK>
  11.           <LOC>Room 543</LOC>
  12.           <FLR>5</FLR>
  13.           <NAM>Joe's Barbershop</NAM>
  14.           <PC>10027-0401</PC>
  15.        </civic-address>
  16.    </location>
  17.    <location>
  18.        <civic-address>
  19.            ...
  20.        </civic-address>
  21.     </location>
  22.    <location>
  23.        <civic-address>
  24.            ...
  25.        </civic-address>
  26.     </location>
  27.  
If any of HNO HNS PRD A6 POD STS are missing, they should just be
ignored. If all of them are missing, then a 'street' element should
not be created.

I am looking for tips on creating an efficient xslt for this.

TIA,
rouble
Jan 14 '09 #1
2 3031
Dormilich
8,658 Expert Mod 8TB
@rouble
well, if you haven't done yet, I recommend reading a tutorial (www.w3schools.com/xslt). then you should try to put the creation of the <street> tag in a separate template. once that is running you need to put it in the copy-procedure (you'll find some copy templates in this forum).

if you're running into problems, just ask us

regards
Jan 15 '09 #2
jkmyoung
2,057 Expert 2GB
If all of them are missing
Do you mean the elements themselves are missing, or there are empty elements? The solution can be quite different with each.

The solution with empty elements is much easier, and looks like:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="A6">
  2.   <xsl:variable name="street">
  3.     <xsl:value-of select="."/>
  4.     <xsl:value-of select="following-sibling::PRD"/>
  5.     <xsl:value-of select="following-sibling::POD"/>
  6.     <xsl:value-of select="following-sibling::STS"/>
  7.     <xsl:value-of select="following-sibling::HNO"/>
  8.     <xsl:value-of select="following-sibling::HNS"/>
  9.   </xsl:variable>
  10.   <xsl:if test="$street != ''">
  11.     <street><xsl:value-of select="$street"/></street>
  12.   </xsl:if>
  13. </xsl:template>
  14. <xsl:template match="PRD|POD|STS|HNO|HNS"/>
  15.  
The other solution requires you to make changes at the civic-address template level, and is much more painful.
Jan 15 '09 #3

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

Similar topics

13
by: Mark Constant | last post by:
I posted this on topxml.com and nobody has responded so I was hoping somebody could help me here. I am following some tutorials in VS.NET. I created a XSD schema file and then from there created an...
3
by: Ndeye | last post by:
Hi all I have this xml file (generated from Lotus Domino 6) and would like to transform it to a simpler one by extracting only data between the gif tag (I cut the gif data to reduce the file...
6
by: Per Jørgen Vigdal | last post by:
I have a XML that I need to map. The XML goes like: <Children> <Child> <References> <External> <Reference name="filename" value="1.dat"/> <Reference name="invoicenr" value="1111111"/>...
0
by: Terry Brown | last post by:
I have an xml file: <?xml version="1.0" encoding="utf-8" ?> <G2Registers xmlns="http://tempuri.org/registers.xsd"> <register> <name>Version Register</name> <address>"00000000"</address>...
34
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ...
3
by: Bostonasian | last post by:
I have following original xml : <HealthHistory> <BloodPressure low="80" high="120" TransactionDate="1/1/2007"/> <BloodPressure low="90" high="140" TransactionDate="1/1/2007"/> <BloodPressure...
8
by: Hercules Dev. | last post by:
Hi all, I'm new in xslt and xpath, so my question might be simple but i'm learning. I have an XML document and need to transform it into another XML, I use xslt and it works, but there is a...
0
by: SpaceMarine | last post by:
hello, im having a discussion w/ one of my associates, and we're are trying to get a consensus on a possible performance scenario. we're working a/ 3-rd party component that produces PDFs using...
1
by: Cinimod | last post by:
Hi, after running the transformation I want the following output: <p:elementName/> therefore I run my xslt as the following: <xsl:variable...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.