Re: [xsl] tricky text and structure test is troubling me

Subject: Re: [xsl] tricky text and structure test is troubling me
From: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 6 Mar 2020 16:53:08 -0000
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@xxxxxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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)

Current Thread