dita-ot / dita-ot

DITA Open Toolkit — the open-source publishing engine for content authored in the Darwin Information Typing Architecture.
https://www.dita-ot.org
Apache License 2.0
404 stars 196 forks source link

Support action="passthrough" for XHTML output #2955

Closed chrispitude closed 2 years ago

chrispitude commented 6 years ago

Expected Behavior

The expected behavior is that the attribute value would be present in the XHTML (either as a class value or in some other form).

Actual Behavior

The actual behavior is that the behavior is the same as "include" - the content is included, but any information about the presence or scope of the attribute is lost.

Possible Solution

Steps to Reproduce

  1. Download

    https://gist.github.com/chrispitude/3dc6ed3e246ca426f1b3b91446da109e

  2. Run

    dita --format xhtml --filter filter.ditaval --input topic.xml --output xhtml

  3. Look at

    xhtml/topic.html

Environment

Working in Windows WSL environment (Ubuntu).

chrispitude commented 6 years ago

Strangely, I did a grep for 'passthrough' in the xhtml XSLT files, and I do see matches:

$ fgrep passthrough dita-ot-3.0.3/plugins/org.dita.xhtml/*/*/*
dita-ot-3.0.3/plugins/org.dita.xhtml/xsl/xslhtml/dita2htmlImpl.xsl:  <xsl:variable name="passthrough-attrs" as="element()*"
dita-ot-3.0.3/plugins/org.dita.xhtml/xsl/xslhtml/dita2htmlImpl.xsl:                select="$FILTERDOC/val/prop[@action = 'passthrough']"/>
dita-ot-3.0.3/plugins/org.dita.xhtml/xsl/xslhtml/dita2htmlImpl.xsl:  <xsl:if test="exists($passthrough-attrs)">
dita-ot-3.0.3/plugins/org.dita.xhtml/xsl/xslhtml/dita2htmlImpl.xsl:      <xsl:if test="$passthrough-attrs[@att = name(current()) and (empty(@val) or (some $v in tokenize(current(), '\s+') satisfies $v = @val))]">

But for some reason, it's not taking effect. There is similar code in the html5 XSLT files:

$ fgrep passthrough dita-ot-3.0.3/plugins/org.dita.html5/*/*
grep: dita-ot-3.0.3/plugins/org.dita.html5/sass/domains: Is a directory
dita-ot-3.0.3/plugins/org.dita.html5/xsl/topic.xsl:    <xsl:variable name="passthrough-attrs" as="element()*"
dita-ot-3.0.3/plugins/org.dita.html5/xsl/topic.xsl:                  select="$FILTERDOC/val/prop[@action = 'passthrough']"/>
dita-ot-3.0.3/plugins/org.dita.html5/xsl/topic.xsl:    <xsl:if test="exists($passthrough-attrs)">
dita-ot-3.0.3/plugins/org.dita.html5/xsl/topic.xsl:        <xsl:if test="$passthrough-attrs[@att = name(current()) and (empty(@val) or (some $v in tokenize(current(), '\s+') satisfies $v = @val))]">

And when I target html5 instead of xhtml, I do see the attributes passed through into the output.

raducoravu commented 6 years ago

From what I remember, and @jelovirt can probably tell us more about this, it was considered that in XHTML-based outputs you cannot have "data-" attributes because they are not part of the XHTML transitional specification. So the passthrough works only for HTML 5. So this XSLT stylesheet:

dita-ot\plugins\org.dita.xhtml\xsl\dita2xhtml-util.xsl

matches all such data- attributes and eliminates them:

     <xsl:template match="@*[starts-with(name(), 'data-')]" mode="add-xhtml-ns" priority="10"/>
raducoravu commented 6 years ago

Linking to the original issue where the passthrough was implemented: https://github.com/dita-ot/dita-ot/issues/1739

raducoravu commented 6 years ago

Initially I would have preferred this to work for any XHTML-based output. For example in our DITA to WebHelp output which is still based on XHTML we have an extra XSLT template which overrides the data- stripping template and preserves the attributes:

   <xsl:template match="@*[starts-with(name(), 'data-')]" mode="add-xhtml-ns" priority="20">
      <xsl:copy/>
  </xsl:template>
robander commented 6 years ago

it was considered that in XHTML-based outputs you cannot have "data-" attributes because they are not part of the XHTML ...

I think that is probably correct. For a long time the same code was used to produce both HTML5 and XHTML; the normal process was to generate HTML5 and then down-grade to XHTML. Eventually the code split (for a lot of good reasons). XHTML is not updated as often at this point, but a lot of the old traces are still there, where HTML5 markup appears to be added but then is removed to create valid XHTML.

chrispitude commented 6 years ago

Thank you Robert and Radu for your replies!

I agree with Radu - it would be nice to pass this in some form - classes, comments, etc- can make the difference between the tool being usable or not for a task. If a user doesn't like the solution, they don't have to use an action of "passthrough" and nothing is lost!

It seems that Radu's team has solved this through XSLT modification. Radu, thanks for your code snippet - I will explore this next!

raducoravu commented 6 years ago

@chrispitude You can try to create a DITA OT plugin which uses the "dita.xsl.xhtml" extension point to provide your own XSLT which tries to override the template which removes the data- attributes.

raducoravu commented 5 years ago

The fix I proposed here does not work. Because of the way "dita2xhtml-util.xsl" is imported (with maximum priority), no XSLT stylesheet from a plugin can override any of the xsl:templates inside it.

markgif commented 5 years ago

I'd like to see this changed, I consider it a bug because HTML5 can be one of at least two syntaxes: HTML and XML, and therefore @data-* attributes should be allowed in the XML syntax. See this from the spec:

https://html.spec.whatwg.org/multipage/introduction.html#html-vs-xhtml

I think it is correct that the XHTML transitional spec does not allow @data-*, but then maybe we should use a different doctype for XML-syntax HTML5, or have an option for more than one doctype for XHTML. Note that the spec above disavows official use of the term "XHTML" although XML-syntax HTML5 is a standard-supported thing.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not been updated recently. It will be closed soon if no further activity occurs. Thank you for your contributions.