Skip to content

Commit ba1fe36

Browse files
committed
TODO: Try to handle external links
1 parent 85f0f3f commit ba1fe36

1 file changed

Lines changed: 85 additions & 12 deletions

File tree

src/docbuild/config/xml/data/convert-v6-to-v7.xsl

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@
430430
<xsl:variable name="id" select="ancestor::product/@productid"/>
431431
<xsl:variable name="ver" select="@setid"/>
432432
<xsl:variable name="subpath" select="concat($id, '/', $ver, '.xml')"/>
433+
<!-- <xsl:variable name="" select=""/>-->
433434

434435
<xsl:variable name="content">
435436
<docset xmlns:xi="http://www.w3.org/2001/XInclude">
@@ -440,13 +441,16 @@
440441
<xsl:otherwise>
441442
<xsl:apply-templates select="@*|node()[not(self::external)]" />
442443

443-
<xsl:if test="external/link[not(starts-with(language/url/@href, 'https://'))]">
444-
<xsl:call-template name="docset-without-builddocs" ></xsl:call-template>
444+
<xsl:if test="external/link[not(starts-with(language/url/@href, 'https://'))
445+
and not(language/url/@format = 'pdf')]">
446+
<xsl:call-template name="docset-without-builddocs" />
445447
</xsl:if>
446448

447-
<xsl:if test="external/link[starts-with(language/url/@href, 'https://')]">
449+
<xsl:if test="external/link[starts-with(language/url/@href, 'https://')
450+
or language/url/@format = 'pdf']">
448451
<external>
449-
<xsl:apply-templates select="external/link[starts-with(language/url/@href, 'https://')]" mode="external-link"/>
452+
<xsl:apply-templates select="external/link[starts-with(language/url/@href, 'https://')
453+
or language/url/@format = 'pdf']" mode="external-link"/>
450454
</external>
451455
</xsl:if>
452456
</xsl:otherwise>
@@ -486,7 +490,7 @@
486490
<xsl:template name="docset-without-builddocs">
487491
<resources>
488492
<git remote="https://TODO" />
489-
<xsl:apply-templates select="external[link[not(starts-with(language/url/@href, 'https://'))]]"
493+
<xsl:apply-templates select="external[link[not(starts-with(language/url/@href, 'https://')) and not(language/url/@format = 'pdf')]]"
490494
mode="builddocs" />
491495
</resources>
492496
</xsl:template>
@@ -495,16 +499,25 @@
495499
<xsl:template match="docset/external" mode="builddocs">
496500
<locale lang="en-us">
497501
<branch>main</branch>
498-
<xsl:apply-templates select="link[not(starts-with(language/url/@href, 'https://'))]" mode="builddocs" />
502+
<xsl:apply-templates select="link[not(starts-with(language/url/@href, 'https://')) and not(language/url/@format = 'pdf')]" mode="builddocs" />
499503
</locale>
500-
<xsl:if test="link[not(starts-with(language/url/@href, 'https://')) and @lang != 'en-us']">
504+
<xsl:if test="link[not(starts-with(language/url/@href, 'https://')) and not(language/url/@format = 'pdf') and @lang != 'en-us']">
501505
<xsl:message>TODO: Found non-English links in docset/external</xsl:message>
502506
</xsl:if>
503507
</xsl:template>
504508

505509
<xsl:template match="link" mode="external-link">
506510
<link>
507-
<xsl:copy-of select="@category|@gated|@titleformat"/>
511+
<xsl:copy-of select="@gated|@titleformat|@category"/>
512+
<!--<xsl:choose>
513+
<xsl:when test="@category">
514+
<xsl:copy-of select="@category"/>
515+
</xsl:when>
516+
<xsl:otherwise>
517+
<xsl:attribute name="category">TODO</xsl:attribute>
518+
</xsl:otherwise>
519+
</xsl:choose>-->
520+
508521
<xsl:for-each select="language/url">
509522
<url>
510523
<xsl:copy-of select="@href|@format"/>
@@ -520,17 +533,36 @@
520533
<xsl:otherwise>en-us</xsl:otherwise>
521534
</xsl:choose>
522535
</xsl:attribute>
523-
<title><xsl:value-of select="@title"/></title>
536+
<xsl:if test="@title">
537+
<title><xsl:value-of select="@title"/></title>
538+
</xsl:if>
539+
<p>TODO</p>
524540
</desc>
525541
</xsl:for-each>
526542
</descriptions>
527543
</link>
528544
</xsl:template>
529545

530546
<xsl:template match="link" mode="builddocs">
531-
<xsl:variable name="href" select="language[@lang='en-us']/url/@href"/>
547+
<xsl:variable name="url" select="language[@lang='en-us']/url"/>
548+
<xsl:variable name="href" select="$url/@href"/>
549+
<xsl:variable name="format" select="$url/@format"/>
550+
532551
<!-- Extract product ID from URL like /product/docset/... -->
533-
<xsl:variable name="pid" select="substring-before(substring-after($href, '/'), '/')"/>
552+
<xsl:variable name="pid">
553+
<xsl:choose>
554+
<xsl:when test="starts-with($href, '/')">
555+
<xsl:value-of select="substring-before(substring-after($href, '/'), '/')"/>
556+
</xsl:when>
557+
<xsl:when test="contains($href, 'external-tree')">
558+
<!-- href="external-tree/en-us/liberty/..." -->
559+
<xsl:value-of select="substring-before(substring-after(substring-after($href, 'external-tree/'), '/'), '/')"/>
560+
</xsl:when>
561+
<xsl:otherwise>
562+
<xsl:value-of select="ancestor::product/@productid"/>
563+
</xsl:otherwise>
564+
</xsl:choose>
565+
</xsl:variable>
534566

535567
<xsl:variable name="abbrev" select="$config/product[@id=$pid]/@idabbrev"/>
536568

@@ -545,6 +577,47 @@
545577
</xsl:choose>
546578
</xsl:variable>
547579

580+
<xsl:variable name="docset_from_url">
581+
<xsl:choose>
582+
<xsl:when test="starts-with($href, '/')">
583+
<xsl:variable name="after_pid" select="substring-after(substring-after($href, '/'), '/')"/>
584+
<xsl:choose>
585+
<xsl:when test="contains($after_pid, '/')">
586+
<xsl:value-of select="substring-before($after_pid, '/')"/>
587+
</xsl:when>
588+
<xsl:otherwise>
589+
<xsl:value-of select="$after_pid"/>
590+
</xsl:otherwise>
591+
</xsl:choose>
592+
</xsl:when>
593+
<xsl:when test="contains($href, 'external-tree')">
594+
<xsl:variable name="after_pid" select="substring-after(substring-after(substring-after($href, 'external-tree/'), '/'), '/')"/>
595+
<xsl:choose>
596+
<xsl:when test="contains($after_pid, '/')">
597+
<xsl:value-of select="substring-before($after_pid, '/')"/>
598+
</xsl:when>
599+
<xsl:otherwise>
600+
<xsl:value-of select="$after_pid"/>
601+
</xsl:otherwise>
602+
</xsl:choose>
603+
</xsl:when>
604+
<xsl:otherwise>
605+
<xsl:value-of select="ancestor::docset/@setid"/>
606+
</xsl:otherwise>
607+
</xsl:choose>
608+
</xsl:variable>
609+
610+
<xsl:variable name="docset_clean">
611+
<xsl:choose>
612+
<xsl:when test="contains($docset_from_url, '.')">
613+
<xsl:value-of select="substring-before($docset_from_url, '.')"/>
614+
</xsl:when>
615+
<xsl:otherwise>
616+
<xsl:value-of select="$docset_from_url"/>
617+
</xsl:otherwise>
618+
</xsl:choose>
619+
</xsl:variable>
620+
548621
<xsl:variable name="filename">
549622
<xsl:call-template name="substring-after-last">
550623
<xsl:with-param name="string" select="$href"/>
@@ -566,7 +639,7 @@
566639
<xsl:variable name="id">
567640
<xsl:call-template name="generate.id">
568641
<xsl:with-param name="product.idabbrev" select="$product.idabbrev"/>
569-
<xsl:with-param name="docset" select="ancestor::docset/@setid"/>
642+
<xsl:with-param name="docset" select="$docset_clean"/>
570643
<xsl:with-param name="dc" select="$doc"/>
571644
</xsl:call-template>
572645
</xsl:variable>

0 commit comments

Comments
 (0)