Subject: Re: [xsl] That's a wrap! From: "Christophe Marchand cmarchand@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 4 Jan 2018 18:08:08 -0000 |
For the loss of punctuation, you should use a for-each-group starts-with=(* except string-name, collab, etal)
Best regards, Christophe
I should probably be posting this to Stack Overflow, where the XSLTquestions 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>-<l page>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>-<l page>38</lpage>.</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):
select="./node()[not(string-name|collab|etal)]"></xsl:apply-templates>
<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
</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>-<l page>38</lpage>.</mixed-citation></ref>
don't understand why
That is, all the stuff I want wrapped is wrapped, but it's also repeated. I
select="./node()[not(string-name|collab|etal)]"></xsl:apply-templates>
<xsl:apply-templates
elements.
(and the many variations of the same I've tried) does not exclude those
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.
978-975-3811
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:
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] That's a wrap!, Charles O'Connor coc | Thread | Re: [xsl] That's a wrap!, Graydon graydon@xxxx |
Re: [xsl] That's a wrap!, Martin Honnen martin | Date | Re: [xsl] That's a wrap!, Charles O'Connor coc |
Month |