简体   繁体   中英

XSLT: combine multiple unrelated elements into one element

I am transforming qualified Dublin Core into MODS. I need to combine two elements into one, and other posts I've found here aren't applicable because they match on a parent element.

Dublin Core is problematic with XSLT because it does not have parent and child elements... so I am not sure which to select.

Here's some sample input (the important bits are the dc:coverage elements):

<?xml version="1.0"?>   
  <oai_dc:dc (schema etc.)>
        <dc:title>This is the title</dc:title>
        <dc:creator>Author McAuthorson</dc:creator>
        <dc:type>Article</dc:type>
        <dc:coverage.spatial.lat>49.101</dc:coverage.spatial.lat>
        <dc:coverage.spatial.long>-122.720</dc:coverage.spatial.long>
  </oai_dc:dc>

And here's the output I need for the dc:coverage elements:

<subject>
  <cartographics>
    <coordinates>49.101, -122.720</coordinates>
  </cartographics>
</subject>

I've read solutions that can process different elements with the same name, but nothing that can combine two elements with different names. I've experimented with setting these up as variables, but can't work out how to pass the variable from one template (eg matching dc:coverage.spatial.lat) into the next (matching dc:coverage.spatial.long). So I'm kind of flying blind.

Any advice (or links to applicable answers that I couldn't find) would be much appreciated.

Why can't you do simply:

<xsl:template match="/oai_dc:dc">
    <subject>
        <cartographics>
            <coordinates>
                <xsl:value-of select="dc:coverage.spatial.lat" />
                <xsl:text>, </xsl:text>
                <xsl:value-of select="dc:coverage.spatial.long" />
            </coordinates>
        </cartographics>
    </subject>
</xsl:template>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM