1
votes

I got the the xml like this

<feature ufi="-1578440">
    <designation>PPLA</designation>  
    <administrative_division>06</administrative_division>
    <name_type>V</name_type>
    <full_name>Hobart Town</full_name>
    <sort_key>HOBARTTOWN</sort_key>
    <modified>2012-02-06</modified>
</feature>
<feature ufi="-1578440">
    <designation>PPLA</designation>
    <administrative_division>06</administrative_division>
    <name_type>N</name_type>
    <full_name>Hobart</full_name>
    <sort_key>HOBART</sort_key>
    <modified>2012-02-06</modified>
</feature>

Basically, the information of 2 fields is similar except the name_type. So I would like to generate the output something like this using xsl grouping.

Hobart (also known as Hobart Town), PPLA, V, 2012-02-06

Could anyone suggest me the simple way to achieve the result. Thanks a lot

Edit: I suppose to do that with xsl version 1 with key is ufi

1
Do you want plain text output as the XSLT transformation result? Do you use XSLT 1.0 or 2.0? And what is the grouping key, is that the ufi attribute value?Martin Honnen
Does it matter which of the <feature> elements is chosen to define the basic name and which are "also known as" names? And is the <name_type> field of any consequence here?Borodin

1 Answers

1
votes

No grouping involved, but this will get the job done (assuming plain text output and disregarding newline stuff, left as an exercise):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output method="text"/>

    <xsl:template match="feature[name_type='N']">
        <xsl:value-of select="full_name"/>
        <xsl:variable name="ufi" select="@ufi"/>
        (also known as <xsl:value-of select="../feature[name_type='V' and @ufi=$ufi]/full_name"/>)
        , <xsl:value-of select="designation"/>, <xsl:value-of select="name_type"/>, <xsl:value-of select="modified"/>
    </xsl:template>

    <xsl:template match="feature"/>
</xsl:stylesheet>

using xslt 2.0 would be much much nicer though..