xsl-list
[Top] [All Lists]

Re: [xsl] That's a wrap!

2018-01-04 12:08:12
<xsl:apply-template select="* except (string-name, collab, etal) | text()"/>

Should do the trick to exclude.


For the loss of punctuation, you should use a for-each-group starts-with=(* except string-name, collab, etal)


Best regards,
Christophe


Le 04/01/2018 à 18:46, Charles O'Connor coconnor(_at_)ariessys(_dot_)com a 
écrit :
I should probably be posting this to Stack Overflow, where the XSLT questions 
are more basic, but anyways . . .

I have a JATS document with references, e.g.:

<ref id="r2"><label>2.</label><mixed-citation publication-type="journal"><string-name name-style="western"><surname>Selvarajah</surname> <given-names>S</given-names></string-name>, <string-name name-style="western"><surname>Hammond</surname> <given-names>ER</given-names></string-name>, <string-name 
name-style="western"><surname>Haider</surname> <given-names>AH</given-names></string-name>, <string-name name-style="western"><surname>Abularrage</surname> <given-names>CJ</given-names></string-name>, <string-name name-style="western"><surname>Becker</surname> <given-names>D</given-names></string-name>, <string-name 
name-style="western"><surname>Dhiman</surname> <given-names>N</given-names></string-name>, <etal>et al.</etal> <article-title>The burden of acute traumatic spinal cord injury among adults in the United States: an update.</article-title> <source>J Neurotrauma</source> 
<year>2014</year>;<volume>31</volume>(<issue>3</issue>):<fpage>228</fpage>-<lpage>38</lpage>.</mixed-!
citation></ref>

I want to remove the <label> and wrap all the <string-name>, <collab>, and <etal> 
elements, and all the space and punctuation in between, in a single <person-group> wrapper, yielding:

<ref id="r2"><mixed-citation publication-type="journal"><person-group><string-name name-style="western"><surname>Selvarajah</surname> <given-names>S</given-names></string-name>, <string-name name-style="western"><surname>Hammond</surname> <given-names>ER</given-names></string-name>, <string-name 
name-style="western"><surname>Haider</surname> <given-names>AH</given-names></string-name>, <string-name name-style="western"><surname>Abularrage</surname> <given-names>CJ</given-names></string-name>, <string-name name-style="western"><surname>Becker</surname> <given-names>D</given-names></string-name>, <string-name 
name-style="western"><surname>Dhiman</surname> <given-names>N</given-names></string-name>, <etal>et al.</etal></person-group> <article-title>The burden of acute traumatic spinal cord injury among adults in the United States: an update.</article-title> <source>J Neurotrauma</source> 
<year>2014</year>;<volume>31</volume>(<issue>3</issue>):<fpage>228</fpage>-<lpage>38</lpa!
ge>.</mixed-citation></ref>

Using my "I've only gotten through 3 hours of the Udemy XSLT course" skills, I 
came up with the following, realizing that I would be losing the spaces and punctuation 
between elements (which I can live with at this point):

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
     xmlns:xs="http://www.w3.org/2001/XMLSchema";
     exclude-result-prefixes="xs"
     version="2.0">
<!--identity template-->
     <xsl:template match="node()|@*">
         <xsl:copy>
             <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
<xsl:template match="ref/label"/> <xsl:template match="mixed-citation">
         <xsl:copy>
          <person-group>
              <xsl:apply-templates select="string-name|collab|etal"/>
         </person-group>
         <xsl:apply-templates 
select="./node()[not(string-name|collab|etal)]"></xsl:apply-templates>
         </xsl:copy>
     </xsl:template>
</xsl:stylesheet>

(Saxon PE 9.7.0.15 in Oxygen)

But that gave me:

<ref id="r2"><mixed-citation><person-group><string-name name-style="western"><surname>Selvarajah</surname> <given-names>S</given-names></string-name><string-name name-style="western"><surname>Hammond</surname> <given-names>ER</given-names></string-name><string-name name-style="western"><surname>Haider</surname> 
<given-names>AH</given-names></string-name><string-name name-style="western"><surname>Abularrage</surname> <given-names>CJ</given-names></string-name><string-name name-style="western"><surname>Becker</surname> <given-names>D</given-names></string-name><string-name name-style="western"><surname>Dhiman</surname> <given-names>N</given-names></string-name><etal>et 
al.</etal></person-group><string-name name-style="western"><surname>Selvarajah</surname> <given-names>S</given-names></string-name>, <string-name name-style="western"><surname>Hammond</surname> <given-names>ER</given-names></string-name>, <string-name name-style="western"><surname>Haider</surname> <given-names!
>AH</given-names></string-name>, <string-name name-style="western"><surname>Abularrage</surname> <given-names>CJ</given-names></string-name>, <string-name name-style="western"><surname>Becker</surname> 
<given-names>D</given-names></string-name>, <string-name name-style="western"><surname>Dhiman</surname> <given-names>N</given-names></string-name>, <etal>et al.</etal> <article-title>The burden of acute traumatic spinal cord injury among adults in the United 
States: an update.</article-title> <source>J Neurotrauma</source> <year>2014</year>;<volume>31</volume>(<issue>3</issue>):<fpage>228</fpage>-<lpage>38</lpage>.</mixed-citation></ref>

That is, all the stuff I want wrapped is wrapped, but it's also repeated. I 
don't understand why

         <xsl:apply-templates 
select="./node()[not(string-name|collab|etal)]"></xsl:apply-templates>

(and the many variations of the same I've tried) does not exclude those 
elements.

How do I exclude them? A bonus would be to know how to preserve the punctuation and spaces 
between the <string-name> (and <collab> and <etal>) elements.

Thanks!
Charles

Charles O'Connor l Business Analyst (not a programmer)
Aries Systems Corporation l www.ariessys.com
200 Sutton Street l North Andover, MA l 01845 l USA
Direct: 802-585-5655 Main: 978-975-7570 l Help Desk: 978-291-1966 | Fax: 
978-975-3811


--~----------------------------------------------------------------
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>