Cheers David
Thanks for the idea of putting the output into a variable and testing it there
- I never seem to think of techniques like that.
This is generating html pages of documentation from XML notes.
Once I have a working test with the example I offered, I have two separate
applications for it.
One is a validity test to identify poorly structured notes - depending on what
the intervening content actually is.
The other is to test whether the output templates should generate a menu of
links to the lower level content. At the moment if there's only one lower level
title in the document the menu isn't generated (because what's the point of a
hyperlink which takes you to the very next line?). But if there is intervening
content then I want to generate this menu after all.
I'll have a play with your suggestion and come back to the list if I'm still
stuck.
Cheers
T
-----Original Message-----
From: David Carlisle d(_dot_)p(_dot_)carlisle(_at_)gmail(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Saturday, 7 March 2020 5:54
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] tricky text and structure test is troubling me
You haven't really said what the output looks like, but you (may) find it
simpler to test the output than the input, that way any file inclusions are
already handled:
<xsl:template match="document">
<xsl:variable name="x">
<xsl:apply-templates/>
</xsl:variable>
<xsl:if test="not($x/node()[1]/self::section)">
<xsl:message select="'something before first section'"/> </xsl:if>
,xsl:sequence select="$x"/> </xsl:template>
The test not($x/node()[1]/self::section) is flagging any node before section,
if <section> gets transformed to (say) <h2> you'd need to look for that
instead, and also you may want to allow white space text nodes, but that's just
details....
David
On Fri, 6 Mar 2020 at 16:38, Trevor Nicholls
trevor(_at_)castingthevoid(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
At least it's proving tricky for me...
Simple case, a piece of XML which looks like this
<document>
<title>document title</title>
... (A) ...
<section>
<title>section title>
... (B) ...
</section>
... (C) ...
</section>
Assuming the current node is the <document>, I need a test which tells me
whether there is going to be any *visible* content in the space labelled (A).
There are complications.
Firstly, it is not sufficient to just look for a text node or img element
within (A) because a couple of elements have text content but are not
rendered by our output stage.
For example, targets.
<document>
<title id="a">document title</title>
<target id="b">alternative title</target>
<section>
<title id="c">section title</title>
...
</section>
</document>
The number of such elements is finite, in fact off the top of my head targets
and footnotes are the only ones.
Secondly, before the XSL process which needs to evaluate this test is run the
input document is pre-processed to pull in any included sub-content. These
inclusions are reflected in the document like so:
<document>
<title id="a">document title</title>
<target id="b">alternative title</target>
<included srcfile="path1.xml">
<included srcfile="path1a.xml">
<section>
<title id="c">section title</title>
...
</section>
</included>
<included srcfile="path1b.xml">
<section>
<title id="d">another section title</title>
...
</section>
</included>
</included>
</document>
I need to be able to tell the difference between the case where - reading in
document order - the document contains a descendant text node (that isn't
part of the document title or a target element), or img element, before the
first section element, and the case where there isn't. I'm probably
overthinking it but after much thought I have yet to arrive at a working
solution.
I hope I have explained this adequately!
Thanks in advance
T
XSL-List info and archive
EasyUnsubscribe (by email)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--