English 中文(简体)
xsl中的分组
原标题:Grouping in xsl
  • 时间:2012-05-27 16:11:26
  •  标签:
  • xml
  • xslt

我得到了这样的xml

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

基本上,除了name_type之外,2个字段的信息是相似的。因此,我想使用xsl分组生成类似这样的输出。

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

有人能给我建议一下实现这一结果的简单方法吗。谢谢

编辑:我想用密钥为ufi的xsl版本1来实现这一点

问题回答

不涉及分组,但这将完成工作(假设纯文本输出,忽略换行符,留作练习):

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

不过,使用xslt2.0会好得多。。





相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签