Xpath for validating if href in xref element is pointing to <fn> element #XSLT


Shaurabh
 

I have a test.dita file which consists of a table element as shown below. As you can see few cells inside <tgroup> element consists of xref element which are targeting to <fn> element. I want to have total count of <xref> elements targeting to <fn> element.
I am able to have the count of xref elements having href attribute using below xpath-

<xsl:variable name="prmElement" select="."/>
<xsl:variable name="fnXCount" select="count($prmElement/descendant::*[contains(@class,' topic/xref ')][@href])"/>

In addition to above, I want to validate if @href is pointing to <fn> element.  Please help me to improve above xpath for fn count validation.
test.dita

<topic id="test_overview">
    <title id="title_id">Test Title</title>
    <body>
        <table>
            <title>My table</title>
            <desc>
                <p>
                    <fn id="fn_5fc">My first footnote.</fn>
                </p>
                <p>
                    <fn id="fn_vfc">My second footnote.</fn>
                </p>
            </desc>
            <tgroup cols="3">
                <colspec colname="col1" colwidth="1.01*" colnum="1"/>
                <colspec colname="col4" colwidth="1.01*" colnum="2"/>
                <colspec colname="col5" colwidth="1*" colnum="3"/>
                <thead>
                    <row>
                        <entry>Col1</entry>
                        <entry>Col2</entry>
                        <entry>Col3</entry>
                    </row>
                </thead>
                <tbody>
                    <row>
                        <entry align="center">Cell <xref
                                href="test.dita#test_overview/fn_5fc"
                            />
                        </entry>
                        <entry align="center">Cell <xref
                                href="test.dita#test_overview/fn_5fc"
                            />
                        </entry>
                        <entry align="center">Cell <xref
                                href="test.dita#test_overview/fn_vfc"
                            />
                        </entry>
                    </row>
                </tbody>
            </tgroup>
        </table>
    </body>
</topic>
 


Regards,
Shaurabh


Chris Papademetrious
 

Hi Shaurabh,

Because <fn> elements with IDs don't generate content themselves, I keep them self-contained inside the table that references them. This way, they move along with the table if I copy/move/conref it to a different topic.

Are you trying to validate that all footnotes are used, and none have gone silently unused?

Is this check going into a Schematron file, or is it being put into some other XSLT file?

 - Chris


Shaurabh
 

Hi Chris,

I am not trying to validate if all footnotes are used or not. I am just trying to find the count for all xrefs which are targeting to footnotes. As i said earlier, I am able to find the count for all xrefs being used inside <tgroup> irrespective of their target element using below xpath-

<xsl:variable name="fnXCount" select="count($prmElement/descendant::*[contains(@class,' topic/xref ')][@href])"/>

  But i want the total count for only those xrefs which are pointing to <fn> element.


Thanks,
Shaurabh


Chris Papademetrious
 

If you are using Oxygen as your editor, there is a setting to always set @type in new <xref> elements:

<xref href="test.dita#test_overview/fn_5fc" type="fn"/>

You can find this setting in Preferences > DITA > Topics, then enable Type in the Always set values for the following attributes list. We use this setting, and it makes this sort of processing and validation much easier.

Otherwise, maybe you could (1) write a function to extract the ID from an @href, (2) put all <fn> ID values in the current document in a variable, and (3) write something like

<xsl:variable name="fnXCount" select="count($prmElement/descendant::*[contains(@class,' topic/xref ')][get_ID(@href) = $all_fn_IDs])"/>

When the '=' operator is given lists, it returns true if there are common items between the lists. In this case, the ID returned by get_ID() would be a list of one string value.

(Disclaimer: I am not an XSLT expert myself.)

 - Chris