Re: [Newbie] Output something using XSLT even if an element is missing in some documents?
- From: Hermann Peifer <peifer@xxxxxxx>
- Date: Sun, 28 Sep 2008 10:26:07 +0200
John Larson wrote:
"John Larson" wrote:My apologies - there was a quote missing right at the end by newline.
After fixing this the tranformation now runs. Sadly the output only
contains the field name and a lot of tabs - none of the content is printed
out (and there is content in some elements that should be there).
The root element of my XML files is "inspec" and each file contains an
number of articles, which is next level down in the tree. The data I want
to extract is in child elements under article. An example XPATH is
"inspec/article/bibliog/jrefg/jrog/vid/vol". Am I somehow pointing
incorrectly or not calling the select correctly or ?
Thanks - John
After a lot of trial and error I figured out that I needed to shorten my
XPATHs in the value of select statements (e.g. from <xsl:value-of
select="inspec/article/contg/accn"/> to <xsl:value-of
select="contg/accn"/>). It now works beautifully - thanks to Hermann for
pointing to this solution.
Best
- John
Good to hear that you got it right.
You could add a leading slash to your select attribute:
<xsl:apply-templates select="/inspec/article"/>
Then, the XSLT processor will only search for inspec/article elements, which are immediately under the root element, and not somewhere in the middle of the XML structure (which might not occur in your XML document, but being as specific as possible is always a good idea, as it also saves processing time).
I assume that each article has max. 1 accn, abgn, etc. elements. If not: you will only get the value of the first one.
Hermann
.
- References:
- [Newbie] Output something using XSLT even if an element is missing in some documents?
- From: John Larson
- Re: [Newbie] Output something using XSLT even if an element is missing in some documents?
- From: Hermann Peifer
- Re: [Newbie] Output something using XSLT even if an element is missing in some documents?
- From: John Larson
- Re: [Newbie] Output something using XSLT even if an element is missing in some documents?
- From: John Larson
- Re: [Newbie] Output something using XSLT even if an element is missing in some documents?
- From: John Larson
- [Newbie] Output something using XSLT even if an element is missing in some documents?
- Prev by Date: Re: XPath query difficulty...
- Next by Date: Restrictions For Elements With The Same Names
- Previous by thread: Re: [Newbie] Output something using XSLT even if an element is missing in some documents?
- Next by thread: Restrictions For Elements With The Same Names
- Index(es):
Relevant Pages
|