Solved

How to rendering tricky XML schema

Posted on 2004-11-01
358 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
Question by:ribbegrd
    1 Comment
     
    LVL 3

    Accepted Solution

    by:
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
    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 viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    933 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

    16 Experts available now in Live!

    Get 1:1 Help Now