Solved

Decoding values From within XSL

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

14 Experts available now in Live!

Get 1:1 Help Now