Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to rendering tricky XML schema

Posted on 2004-11-01
3
Medium Priority
?
367 Views
Last Modified: 2013-11-19
My XML document is as follows:

      <DataSet>
      <xs:schema id="NewDataSet">
      <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="sv-SE">
      <xs:complexType>
      <xs:choice maxOccurs="unbounded">
      <xs:element name="Table">
      <xs:complexType>
      <xs:sequence>
<xs:element name="Origin" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
      <diffgr:diffgram>
      <NewDataSet>
      <Table diffgr:id="Table1" msdata:rowOrder="0">
<Origin>Göteborg/Landvetter GOT</Origin>
</Table>
      <Table diffgr:id="Table2" msdata:rowOrder="1">
<Origin>Helsingborg/Ängelholm AGH</Origin>
</Table>
      <Table diffgr:id="Table3" msdata:rowOrder="2">
<Origin>Helsinki/Vantaa HEL</Origin>
</Table>
      <Table diffgr:id="Table4" msdata:rowOrder="3">
<Origin>Malmö/Sturup MMX</Origin>
</Table>
      <Table diffgr:id="Table5" msdata:rowOrder="4">
<Origin>Stockholm/Arlanda ARN</Origin>
</Table>
</NewDataSet>
</diffgr:diffgram>
</DataSet>


What I would like is a piece of XSL that loops through the list of tags called "<Origin>".

Thanks in advance.
0
Comment
Question by:ribbegrd
[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
3 Comments
 
LVL 3

Accepted Solution

by:
DitmarBehn earned 500 total points
ID: 12464783
Hi ribbegrd,
this should do the trick (note that there are three different ways within the following XLS)
Ditmar


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:diffgr='mydiffgr' >
<!--
***********************************************************************
*** Author:    Ditmar Behn
*** Date:      2004-11-01
*** Origin:    www.experts-exchange.com
***********************************************************************
-->

  <!-- Start the pattern matching mechanism in the root element -->
  <xsl:template match="/">
    <root>
      <!-- Either find all occurances of 'Origin' anywhere -->
      <xsl:for-each select="//Origin">
        <xsl:value-of select="text()" />
      </xsl:for-each>

      <!-- or state explicitly the nodetree location -->
      <xsl:for-each select="DataSet/diffgr:diffgram/NewDataSet/Table/Origin">
        <xsl:value-of select="text()" />
      </xsl:for-each>

    </root>
  </xsl:template>


  <!-- or use pattern matching (document order) to be called by xsl:apply-template -->
  <xsl:template match="Origin">
    <xsl:value-of select="text()" />
  </xsl:template>


</xsl:stylesheet>
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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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. 
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

610 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