Solved

Decoding values From within XSL

Posted on 2001-09-12
2
218 Views
Last Modified: 2006-11-17
I have the following (sample) XML:

<Customers>
  <Name>John Doe</Name>
  <CityCode>NYC</CityCode>
  <Name>Alan Smith</Name>
  <CityCode>LAN</CityCode>
  ...
</Customers>

And want (if possible from within the transforming XSL) to decode the value of <CityCode> from the following XML:

<Cities>
  <CityCode>NYC<Name>New York</Name></CityCode>
  <CityCode>LAN<Name>Los Angeles</Name></CityCode>
</Cities>

I'm at my wits end on how to do this. Thanks


0
Comment
Question by:JFont
2 Comments
 
LVL 4

Accepted Solution

by:
chabaud earned 100 total points
ID: 6478827
First of all, your pb would be easier to resolve if you can reformulate your Xml file, wrapping customers en cities into elements. Note also that City's Name is not a child of CityCode but of City:

<Customers>
 <Customer>
  <Name>John Doe</Name>
  <CityCode>NYC</CityCode>
 </Customer>
 <Customer>
  <Name>Alan Smith</Name>
  <CityCode>LAN</CityCode>
 </Customer>
</Customers>

<Cities>
 <City>
  <CityCode>NYC</CityCode><Name>New York</Name>
 </City>
 <City>
  <CityCode>LAN</CityCode><Name>Los Angeles</Name>
 </City>
</Cities>

Then Xsl file could be simple:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         version="1.0" >

<xsl:output method="html"/>

<xsl:template match="*">
 <xsl:apply-templates/>
</xsl:template>

<xsl:template match="/">
<table border="1">
 <tr><th>Name</th><th>CityCode</th><th>CityName</th></tr>
 <xsl:apply-templates/>
</table>
</xsl:template>

<xsl:template match="Customer">
 <tr>
  <td><xsl:value-of select="Name"/></td>
  <td><xsl:value-of select="CityCode"/></td>
  <td><xsl:value-of select="//City[CityCode=current()/CityCode]/Name"/></td>
 </tr>
</xsl:template>

<xsl:template match="City">
</xsl:template>

</xsl:stylesheet>
0
 

Author Comment

by:JFont
ID: 6479255
Not only excellent, but very elegant. Thanks.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
read PayflowPro reports using the report metadata using perl 11 36
Merge XML into DOM 5 37
Unable to resolve XML http request 4 75
Detect file exist or not 3 132
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now