xsl-list
[Top] [All Lists]

Re: [xsl] XSLT for ditaval filtering

2022-02-01 15:27:02
Hi Chris,

Go with Eliot's solution if you want to do "real DITA". If you want to do
something on the cheap, you could factor our some of the logic

<xsl:variable name="exclusions" select="$ditaval//prop[@att='product' and
@action='exclude']"/>

<xsl:template match="*[@product=$exclusions/@val]"/>

Or for an in-between capability, deploy a key, then match the node with a
template something like

<xsl:template match="*[exists(key('exclusions',@product,$ditaval))]"/>

Like Eliot's function, the key declaration can have fairly complex logic if
it needs to, for binding elements to inclusion or exclusion rules.

Cheers, Wendell

On Tue, Feb 1, 2022 at 3:36 PM Eliot Kimber 
eliot(_dot_)kimber(_at_)servicenow(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

I would create an XSLT function that does the ditaval evaluation so that
you can then use that bindly from match expressions, i.e.:



<xsl:function name=”local:isIncluded” as=”xs:Boolean”>
  <xsl:param name=”context” as=”element()”/>

  <xsl:param name=”ditaval” as=”document-node()”/>



<xsl:variable name=”result” as=”xs:boolean”>

  <!—hard work goes here -->

</xsl:variable>

<xsl:sequence select=”$result”/>

</xsl:function>



And then in your template you can do:



    <xsl:template match="*[not(local:isIncluded(., $ditaval))]"/>



Or maybe the better name is isExcluded() so your check can be
local:isExcluded() but you get the idea.



From the DITAVAL file you can get the names of the attributes (or @props
values) to check and then have generic code that evaluates them.



When I’ve done this in the past I seem to recall normalizing all the
@props specializations to the @props syntax and then evaluating that, but
with XSLT 3 you could use XPath maps, which would be easier, i.e.:



<xsl:variable name=”propsValues” as=”map(*)”>

  <xsl:map-merge>

    <xsl:apply-templates select=”./@*” mode=”get-props-values”/>

  <xsl:map-merge>

</xsl:variable>



Where the keys are condition names and the values are a sequence of
Booleans. You could then use map-left() to get the effective Boolean value
for each condition and compare it to the include/exclude value.



Or maybe I’m making it too hard.



Cheers,



E.

_____________________________________________

*Eliot Kimber*

Sr Staff Content Engineer

O: 512 554 9368

M: 512 554 9368

servicenow.com <https://www.servicenow.com>

LinkedIn <https://www.linkedin.com/company/servicenow> | Twitter
<https://twitter.com/servicenow> | YouTube
<https://www.youtube.com/user/servicenowinc> | Facebook
<https://www.facebook.com/servicenow>



*From: *rick(_at_)rickquatro(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
*Date: *Tuesday, February 1, 2022 at 12:25 PM
*To: *xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
*Subject: *Re: [xsl] XSLT for ditaval filtering

*[External Email]*



Here is my first attempt, which is doing the filtering. With this
algorithm, I would need multiple rules for testing other possible ditaval
attributes.



<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

    xmlns:xs="http://www.w3.org/2001/XMLSchema";

    xmlns:math="http://www.w3.org/2005/xpath-functions/math";

    exclude-result-prefixes="xs math"

    version="3.0" expand-text="yes">



    <xsl:output indent="yes"/>



    <xsl:param name="ditaval-file"
select="'file:///C:/DATA-10/content/Hide-Prod2.ditaval'"/>



    <xsl:variable name="ditaval" as="document-node()*">

        <xsl:if test="doc-available($ditaval-file)=true()">

            <xsl:sequence select="doc($ditaval-file)"/>

        </xsl:if>

    </xsl:variable>



    <xsl:template match="/map">

        <map>

            <xsl:apply-templates select="@*"/>

            <xsl:apply-templates/>

        </map>

    </xsl:template>



    <xsl:template match="*[@product!=''][$ditaval//prop[@att='product' and
@val=current()/@product and @action='exclude']]"/>

    <xsl:mode on-no-match="shallow-copy"/>



</xsl:stylesheet>



XSL-List info and archive
<https://urldefense.com/v3/__http:/www.mulberrytech.com/xsl/xsl-list__;!!N4vogdjhuJM!Sv6gz33vX2VZwdjnjFmgR1wfcLtcokfNrGU4X5oP6uzNiwqROmqKE7dnNqkzprhT-HgjsQ$>

EasyUnsubscribe
<https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsub/xsl-list/3453418__;!!N4vogdjhuJM!Sv6gz33vX2VZwdjnjFmgR1wfcLtcokfNrGU4X5oP6uzNiwqROmqKE7dnNqkzprjWm91pfg$>
(by email)
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/174322> (by
email <>)



-- 
...Wendell Piez... ...wendell -at- nist -dot- gov...
...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>