Из xml хотите получить номер подглавы подглавы во внешней ссылке в html с помощью XSL - PullRequest
0 голосов
/ 09 июля 2020

From xml хотите получить номер подглавы подглавы во внешней ссылке в html с помощью XSL. Я не могу подсчитать и получить правильную нумерацию подразделов в тексте ссылки xref.

сценарий в xml

xref добавлен в подраздел 2.2 и относится к подразделу 1.2, подраздел 2.1 и 1.3

Ожидаемый результат в html из xml

В html к выходной ссылке должен быть добавлен правильный номер, такой как Подраздел 1.2, Подраздел 2.1 и Подраздел 1.3 соответственно.

Примечание: Номер в подразделах 1.1, 1.2, 1.3 и c дан для справки и для лучшего понимания.

Требуется решение - необходимо подсчитайте последовательность глав и подглав, чтобы получить правильный номер подглавы в ссылке xref.

Пример xml (глава упоминается в диагностическом_адре / диагностическом_адре, а подраздел - как диагностический_адт / диагностический_адр / диагностический_адр).

<diagnostic_adt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" appl="" id="TEMPLATE" xml:lang="en" xsi:noNamespaceSchemaLocation="urn:ptc:names:renault:dita:xsd:diagnostic_adt.xsd">
   <diagtitle translate="yes">Test xref</diagtitle>
   <diagbody>
   </diagbody>
   <diagnostic_adt id="idSE1">
      <diagtitle translate="yes">chapter 1</diagtitle>
      <diagbody>
         <para translate="yes">
            To return to the previous screen, click here:
            <END-PROCEDURE />
         </para>
      </diagbody>
      <diagnostic_adt id="idT1">
         <diagtitle translate="yes">sub-chapter 1.1</diagtitle>
         <diagbody>
            <para translate="yes">Test</para>
         </diagbody>
      </diagnostic_adt>
      <diagnostic_adt id="idT2">
         <diagtitle translate="yes">sub-chapter 1.2</diagtitle>
         <diagbody>
            <para translate="yes">Test</para>
         </diagbody>
      </diagnostic_adt>
      <diagnostic_adt id="idT5">
         <diagtitle translate="yes">sub-chapter 1.3</diagtitle>
         <diagbody>
            <para translate="yes">Test</para>
            <para translate="yes">
               <xref format="dita" href="#idT2" scope="local" translate="yes" type="diagnostic_adt" />
            </para>
         </diagbody>
      </diagnostic_adt>
   </diagnostic_adt>
   <diagnostic_adt id="idSE2">
      <diagtitle translate="yes">chapter 2</diagtitle>
      <diagbody>
         <para translate="yes">
            To return to the previous screen, click here:
            <END-PROCEDURE />
         </para>
      </diagbody>
      <diagnostic_adt id="idT3">
         <diagtitle translate="yes">sub-chapter 2.1</diagtitle>
         <diagbody>
            <para translate="yes">
               <xref format="dita" href="#idT2" scope="local" translate="yes" type="diagnostic_adt" />
            </para>
            <para translate="yes">
               <xref format="dita" href="#idT5" scope="local" translate="yes" type="diagnostic_adt" />
            </para>
            <para translate="yes">
               <xref format="dita" href="#idT4" scope="local" translate="yes" type="diagnostic_adt" />
            </para>
         </diagbody>
      </diagnostic_adt>
      <diagnostic_adt id="idT4">
         <diagtitle translate="yes">sub-chapter 2.2</diagtitle>
         <diagbody>
            <para translate="yes">
               <xref format="dita" href="#idT3" scope="local" translate="yes" type="diagnostic_adt" />
            </para>
            <para translate="yes">
               <xref format="dita" href="#idT5" scope="local" translate="yes" type="diagnostic_adt" />
            </para>
            <para translate="yes">
               <xref format="dita" href="#idT2" scope="local" translate="yes" type="diagnostic_adt" />
            </para>
         </diagbody>
      </diagnostic_adt>
   </diagnostic_adt>
</diagnostic_adt>

образец xsl, и этот xsl содержит несколько условий

<xsl:template match="xref">
    <xsl:choose>
        <xsl:when test="contains(@href, '/')">
            <xsl:variable name="xrefid" select="substring-after(translate(@href, '#', ''), '/')"/>
            
            <xsl:variable name="countN">
                <xsl:choose>
                    <xsl:when test="contains($xrefid,'idSE')">
                        <xsl:value-of select="count(//diagnostic[contains(@id,$xrefid)]/preceding-sibling::*[name()='diagnostic'])+1" />
                    </xsl:when>
                    <xsl:when test="contains($xrefid,'idT')">
                        <xsl:choose>
                            <xsl:when test="contains($xrefid,'idTa')">
                                <xsl:value-of select="count(//table[contains(@id,$xrefid)]/preceding-sibling::*[name()='table'])+1"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="count(//diagnostic_adt[contains(@id,$xrefid)]/preceding-sibling::*[name()='diagnostic_adt'])+1"/>
                            </xsl:otherwise>
                        </xsl:choose>   
                    </xsl:when>
                </xsl:choose>
            </xsl:variable>

            <xsl:variable name="nomN">
                <xsl:choose>
                    <xsl:when test="contains($xrefid,'idSE')">
                        <xsl:call-template name="get-label"><xsl:with-param name="code" select="'SECTION'"/></xsl:call-template>
                    </xsl:when>
                    <xsl:when test="contains($xrefid,'idT')">
                        <xsl:choose>
                            <xsl:when test="contains($xrefid,'idTa')">
                                <xsl:call-template name="get-label"><xsl:with-param name="code" select="'TABLE'"/></xsl:call-template>
                            </xsl:when>
                            <xsl:otherwise>
                                <!--<xsl:call-template name="get-label"><xsl:with-param name="code" select="'SOUS-SECTION'"/></xsl:call-template>-->
                                <xsl:text>sub-section: </xsl:text>
                            </xsl:otherwise>
                        </xsl:choose>   
                    </xsl:when>
                </xsl:choose>
            </xsl:variable>
            
            <script type="text/javascript">
                generateIntXref( "<xsl:call-template name="get-label"><xsl:with-param name="code" select="'CLIQUER-ICI'"/></xsl:call-template> <xsl:text>click here: </xsl:text><i>(<xsl:value-of select='$nomN'/>
         <xsl:value-of select='$countN'/>)</i>.", "<xsl:value-of select='$xrefid'/>", "<xsl:value-of select='$countN'/>" );
            </script>
        </xsl:when>
        <xsl:otherwise>
            <xsl:variable name="xrefid" select="translate(@href, '#', '')"/>
            <xsl:variable name="countN">
                <xsl:choose>
                    <xsl:when test="contains($xrefid,'idSE')">
                        <xsl:value-of select="count(//diagnostic[contains(@id,$xrefid)]/preceding-sibling::*[name()='diagnostic'])+1" />
                    </xsl:when>
                    <xsl:when test="contains($xrefid,'idT')">
                        <xsl:choose>
                            <xsl:when test="contains($xrefid,'idTa')">
                                <xsl:value-of select="count(//table[contains(@id,$xrefid)]/preceding-sibling::*[name()='table'])+1"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="count(//diagnostic[contains(@id,$xrefid)]/preceding-sibling::*[name()='diagnostic'])+1"/>                             
                                
                            </xsl:otherwise>
                        </xsl:choose>   
                    </xsl:when>
                </xsl:choose>
            </xsl:variable>

            <xsl:variable name="nomN">
                <xsl:choose>
                    <xsl:when test="contains($xrefid,'idSE')">
                        <xsl:call-template name="get-label"><xsl:with-param name="code" select="'SECTION'"/></xsl:call-template>
                    </xsl:when>
                    <xsl:when test="contains($xrefid,'idT')">
                        <xsl:choose>
                            <xsl:when test="contains($xrefid,'idTa')">
                                <xsl:call-template name="get-label"><xsl:with-param name="code" select="'TABLE'"/></xsl:call-template>
                            </xsl:when>
                            <xsl:otherwise>
                                <!--<xsl:call-template name="get-label"><xsl:with-param name="code" select="'SOUS-SECTION'"/></xsl:call-template>-->
                                <xsl:text>sub-section: </xsl:text>
                            </xsl:otherwise>
                        </xsl:choose>   
                    </xsl:when>
                </xsl:choose>
            </xsl:variable>
            
            <script type="text/javascript">
                generateIntXref( "<xsl:call-template name="get-label"><xsl:with-param name="code" select="'CLIQUER-ICI'"/></xsl:call-template><i>(<xsl:value-of select='$nomN'/>
         <xsl:value-of select='$countN'/>)</i>.", "<xsl:value-of select='$xrefid'/>", "<xsl:value-of select='$countN'/>" );
            </script>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
...