0

input xml:

<body>
    <ce:sections>
        <ce:section>
            <ce:label>1</ce:label>
            <ce:section-title>Introduction and main results</ce:section-title>
            <ce:para> The existence of a globally hyperbolic Lorentzian metric on a 
                <mml:math>(3 + 1)</mml:math>
                -spacetime with closed Cauchy surface excludes all but one differentiable structure on the underlying manifold, as observed by ChernovNemirovski 
                <citegroup>[
                    <cite>
                        <no>CN13</no>
                        <id>CN</id>
                    </cite>
                ]</citegroup>
            </ce:para>
        </ce:section>
    </ce:sections>
</body>

how to check the <mml:math>....</mml:math> and <citegroup>...</citegroup> are the child element of body/ce:section/ce:sections path in input xml using xslt?

how to get the path of <mml: math> using xslt?

Reinder Wit
  • 6,490
  • 1
  • 25
  • 36
Anitha
  • 111
  • 2
  • 12
  • They are not _child_ elements of `ce:section` in this example. They're _descendants_ of the `section` element, but _children_ of the `para`. – Ian Roberts Sep 12 '14 at 12:12
  • i agree its not a child element. its a descendant of ce:section . i want to know how to get the path of mml:math and how do check whether it is descendant of ce:section? – Anitha Sep 12 '14 at 12:16

1 Answers1

0

To check if one node descends from another, use ancestor. For example:

<xsl:template match="mml:math">
  <xsl:if test="ancestor::ce:section">
    <xsl:text>This math node IS inside a section</xsl:text>
  </xsl:if>
</xsl:template>

How to determine a node's path has been asked over here. You may find ideas that help in that discussion.

Community
  • 1
  • 1
biscuit314
  • 2,384
  • 2
  • 21
  • 29
  • You don't need a test. Just do `match="mml:match[ancestor::cd:section]"`. Your approach will "eat" *all* `mml:math` elements, not just the ones he wants. –  Sep 12 '14 at 13:37
  • I understood the question to be "given a `mml:math` how can I know it descends from a `ce:section`". The example demonstrates how `ancestor` answers that question. This template itself is otherwise useless. The questioner can adapt the idea to however a reference to any `mml:math` is obtained – biscuit314 Sep 12 '14 at 13:56
  • 1
    Just guessing, but perhaps the OP is like many procedural people coming to XSLT, who will say things like "check for" when they mean "write rules which only apply to". If you really really need to "check" for something, sure, use an `xsl:if`, but in my experience in the majority of cases this is a "code smell", like `xsl:for-each` often is, of trying to code XSLT in an imperative style. –  Sep 12 '14 at 16:45
  • @torazaburo Well said. – biscuit314 Sep 12 '14 at 17:04