xsl-list
[Top] [All Lists]

Re: [xsl] Tokenizing mixed content

2019-05-17 08:29:37
On 17.05.2019 15:22, Edward Porter edward(_dot_)porter(_at_)sas(_dot_)com wrote:
I am working on a conversion script transforming from a prior DTD to a
new DTD, and as part of this transformation, we are hoping to parse some
mixed content into separate nested elements. The content is “|”
delimited, but I am having a tough time coming up with a way to group
the text and sibling elements. What follows are some permutations of
input and expected output:

INPUT:

<argument> "AUTO | NONE | METADATA"</argument>

OUTPUT:

<argument><choice>AUTO</choice><choice>NONE</choice><choice>METADATA</choice>"</argument>

INPUT:

<argument><userSuppliedValue>dimension</userSuppliedValue> |
<userSuppliedValue>dimension</userSuppliedValue>%</argument>

OUTPUT:

<argument><choice><userSuppliedValue>dimension</userSuppliedValue></choice><choice><userSuppliedValue>dimension></userSuppliedValue>%</choice></argument>

INPUT:

<argument>#BYVAL<userSuppliedValue>n</userSuppliedValue> |
#BYVAL(<userSuppliedValue>BY-variable-name</userSuppliedValue>)</argument>

OUTPUT:

<argument><choice>#BYVAL<userSuppliedValue>n</userSuppliedValue></choice><choice>#BYVAL(<userSuppliedValue>BY-variable-name</userSuppliedValue>)</choice></argument>

I’ve got access to XSL 2, and possibly XSL3 if necessary.


A two pass transformation that first processes text nodes to "convert"
the pipe character into an element (e.g. <pipe/>) and then in second
step uses for-each-group group-ending-with="pipe" should help.
--~----------------------------------------------------------------
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>