Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Decoding values From within XSL

Posted on 2001-09-12
2
Medium Priority
?
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
chabaud earned 400 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

660 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