Solved

Decoding values From within XSL

Posted on 2001-09-12
2
221 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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