This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: display parts of XML tree with xsl:copy ?


Hi Robert,

> This will be done by an XML-formated query in the form of:
[snip]
> As I use standard namespace domains like Dublin Core an the Source
> doc might not have element/attribs of that ns, I also provide an
> XML-formated source description which a: maps those standardized dc:
> stuff into the doc's own names. This descriptor doc will also hold
> information on the supertree that should be inserted to the query
> result when a certain element is part of a condition.

I think I understand. So you have two sources of information:

  - a description of what you want to keep when there's a query for a
    particular type of element
  - a query into that XML document

> As I can never be sure that there is not valuable info in the
> supertree the only thing I sure want to get rid is other brother
> <article>'s, that don't fullfil the query.

But in an earlier example you also said that you didn't want to keep
issue elements that, after filtering, didn't contain any article
elements (when they were the things that you were after).

So I think that if you have:

  - $nodes - the nodes that you want to keep
  - $type - the name of the elements that you are searching for

Then you want to discard elements that (a) do not have any $nodes as
descendants (and aren't themselves in the $nodes) and (b) are
themselves, or do have as descendants, nodes named $type.

Which means that the following template should do it for you:

<xsl:variable name="nnodes" select="count($nodes)" />

<xsl:template match="*">
  <xsl:variable name="descendants"
                select="descendant::*[name() = $type]" />
  <xsl:choose>
    <xsl:when test="not($descendants)">
      <xsl:copy-of select="." />
    </xsl:when>
    <xsl:when test="$descendants[count(.|$nodes) = $nnodes)]">
      <xsl:copy>
        <xsl:copy-of select="@*" />
        <xsl:apply-templates />
      </xsl:copy>
    </xsl:when>
    <!-- otherwise the element contains nodes of the specified type,
         but they aren't the ones you're interested in -->
  </xsl:choose>
</xsl:template>

Of course how you get $nodes and $type is up to you - you could
generate a stylesheet to do it, or try to interpret the description
and the query on the fly.

Is that more like it?

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]