Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How to get node in the order the xml is given

From: Cerebrus <zorg007@----.--->
To: NULL
Date: 6/29/2009 10:31:00 AM
In the example you have provided, it is not the document order which
is a cause of concern, rather it is the fact that the immediate
childnode of the catalog element is not constant. Such cases are
handled via a wildcard based XPath expression or using axes.

So, the following expressions will work:

a) /catalog/*
b) /catalog/child::*
c) /catalog/child::node() - Does not work correctly if you have
whitespace in the source XML because it also matches whitespace.

Neil Smith's example works perfectly and is what you asked for, but
rather than a for-each iteration, I would do via a template match:

---
<x:template match=3D"/">
  <SomeCatalog>
    <x:apply-templates />
  </SomeCatalog>
</x:template>

<x:template match=3D"catalog/*">
  <TheTitle>
    <x:value-of select=3D"title"/>
  </TheTitle>
</x:template>
---

As a side note, I always consider such kind of XML sources to be
poorly designed. if you are free to modify the XML source, it would be
better put as:

---
<catalog>
  <disk type=3D"cd">
  ...
  <disk type=3D"dvd">
  ...
  <disk type=3D"bluray">
  ...
</catalog>
---
This would avoid the problem of having to use wildcards, altogether.

--
Cerebrus.

On Jun 28, 5:41=A0pm, naijacoder <luro...@gmail.com> wrote:
> hahaha Martin.Sorry for being a pain,
> Sorry but i know more than tha tutorial you sent.
> I don't think you really understand what 'm trying to achieve
> When you said i can use xsl:for-each to be process xml in document
> order.
> What i'm after is instead of using xsl:apply-templates =A0to match
> elements how can i use xsl:for-each
> I know i can do
>
> <catalog>
> =A0 =A0 =A0 =A0 <cd>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <title>Empire Burlesque</title>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <artist>Bob Dylan</artist>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <country>USA</country>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <company>Columbia</company>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <price>10.90</price>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <year>1985</year>
> =A0 =A0 =A0 =A0 </cd>
> <cd>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <title>Empire Burlesque</title>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <artist>Bob Dylan</artist>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <country>USA</country>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <company>Columbia</company>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <price>10.90</price>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <year>1985</year>
> =A0 =A0 =A0 =A0 </cd>
> =A0 =A0 =A0 =A0 </catalog>
>
> <xsl:for-each select=3D"catalog/cd">
> =A0 =A0 =A0 =A0 <tr>
> =A0 =A0 =A0 =A0 =A0 <td><xsl:value-of select=3D"title"/></td>
> =A0 =A0 =A0 =A0 =A0 <td><xsl:value-of select=3D"artist"/></td>
> =A0 =A0 =A0 =A0 </tr>
> =A0 =A0 =A0 </xsl:for-each>
>
> But regarding my own xml the <cd> won't be constant
> So i could have
>
> <catalog>
> =A0 =A0 =A0 =A0 <cd>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <title>Empire Burlesque</title>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <artist>Bob Dylan</artist>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <country>USA</country>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <company>Columbia</company>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <price>10.90</price>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <year>1985</year>
> =A0 =A0 =A0 =A0 </cd>
> <dvd>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <title>Empire Burlesque</title>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <artist>Bob Dylan</artist>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <country>USA</country>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <company>Columbia</company>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <price>10.90</price>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <year>1985</year>
> =A0 =A0 =A0 =A0 </dvd>
> <bluray>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <title>Empire Burlesque</title>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <artist>Bob Dylan</artist>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <country>USA</country>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <company>Columbia</company>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <price>10.90</price>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <year>1985</year>
> =A0 =A0 =A0 =A0 </bluray>
> =A0 =A0 =A0 =A0 </catalog>
>
> How can i use xsl:for-each
> to process the document order as they come.
> I know i'm missing something ....
> Thanks Martin
>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent