English 中文(简体)
缩略语
原标题:XSLT 1.0 Grouping on multiple values on multiple levels
  • edited in response to comments *

Hello,

我是欧洲空间法中心的一个口号,需要一些帮助。 我试图与XSLT 1.0(用于这一应用的XSLT 2.0)。

这里的例子就是xml

<entry>
  <item>
    <name>Widget 2</name>
    <rank>2</rank>
    <types>
       <type>Wood</type>
       <type>Fixed</type>
       <type>Old</type>
    </types>
  </item>
   <item>
    <name>Widget 1</name>
    <rank>2</rank>
    <types>
       <type>Metal</type>
       <type>Broken</type>
       <type>Old</type>
    </types>
  </item>
  <item>
    <name>Widget 3</name>
    <rank>1</rank>
    <types>
       <type>Metal</type>
       <type>New</type>
    </types>
  </item>
</entry>

现在,我想做的是产出html,在产出中,我获得了以<代码>和t;类型和“;

<p class="nospace"><font color="#800000">
<b>Rank 1</b></font></p>
<li id="mylist"><b>Widget 3</b></li>
<br>

<p class="nospace"><font color="#800000">
<b>Rank 2</b></font></p>
<li id="mylist"><b>Widget 1</b></li>
<br>

用户选择类型 产出原由

<p class="nospace"><font color="#800000">
<b>Rank 2</b></font></p>
<li id="mylist"><b>Widget 1</b></li>
<li id="mylist"><b>Widget 2</b></li>
<br>

我可以轻而易举地集中使用排名上的钥匙,但试图这样做并不奏效。 这里是我尝试的Xslt样本:

<xsl:param name="typeParam"/>
<xsl:key name="byRank" use="rank" match="item"/>

<xsl:for-each select="item[count(.|key( byRank ,rank)[1])=1]">
  <xsl:sort data-type="number" select="rank"/>
  <xsl:for-each select="key( byRank ,rank)">
    <xsl:sort select="name"/>
    <xsl:if test="count(rank)&gt;0">
      <p class="nospace"><font color="#800000"><b>Rank<xsl:value-of select="rank"/></b></font></p>
      <xsl:for-each select="types[types=$typeParam]">
        <li id="mylist"><b><xsl:value-of select="../name"/></b></li>
      </xsl:for-each>
    <br/>
  </xsl:if>
</xsl:for-each>
</xsl:for-each>

我从中得出的结果是,我确实获得了我所希望的轮椅子,但也显示了所有各级价值观。 我只想把它限制在类巴拉姆具体规定的级别上。

我试图将每份声明移至法典的较早之处,并修改如果要选择哪一种类型的Param,但两者都没有奏效的话。 我也试图将我的关键与级别和类型混为一谈,但似乎没有做任何工作(只有用美元打字的类型是首批类型儿童的情况下才能工作)。

增 编

垃圾

最佳回答

这一风格:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:key name="kItemByRank" match="item" use="rank"/>
    <xsl:param name="pType" select=" Old "/>
    <xsl:template match="entry">
        <xsl:for-each select="item[count(.|key( kItemByRank ,rank)[1])=1]">
            <xsl:sort select="rank" data-type="number"/>
            <xsl:variable name="vGroup" select="key( kItemByRank ,rank)[
                                                   types/type = $pType
                                                ]"/>
            <xsl:if test="$vGroup">
                <p class="nospace">
                    <font color="#800000">
                        <b>
                            <xsl:value-of select="concat( Rank  ,rank)"/>
                        </b>
                    </font>
                </p>
                <xsl:apply-templates select="$vGroup">
                    <xsl:sort select="name"/>
                </xsl:apply-templates>
                <br/>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    <xsl:template match="item">
        <li id="mylist">
            <b>
                <xsl:value-of select="name"/>
            </b>
        </li>
    </xsl:template>
</xsl:stylesheet>

产出:

<p class="nospace">
    <font color="#800000">
        <b>Rank 1</b>
    </font>
</p>
<li id="mylist">
    <b>Widget 3</b>
</li>
<br />
<p class="nospace">
    <font color="#800000">
        <b>Rank 2</b>
    </font>
</p>
<li id="mylist">
    <b>Widget 1</b>
</li>
<br />

∗ ∗ 类型 产出:

<p class="nospace">
    <font color="#800000">
        <b>Rank 2</b>
    </font>
</p>
<li id="mylist">
    <b>Widget 1</b>
</li>
<li id="mylist">
    <b>Widget 2</b>
</li>
<br />
问题回答

暂无回答




相关问题
When test hanging in an infinite loop

I m tokenising a string with XSLT 1.0 and trying to prevent empty strings from being recognised as tokens. Here s the entire function, based on XSLT Cookbook: <xsl:template name="tokenize"> ...

quick xslt for-each question

Let s say I have an XML document that has this: <keywords> <keyword>test</keyword> <keyword>test2</keyword> <keyword>test3</keyword> <keyword>test4</...

XSLT Transform XML with Namespaces

I m trying to transform some XML into HTML using XSLT. Problem: I can t get it to work. Can someone tell me what I m doing wrong? XML: <ArrayOfBrokerage xmlns:i="http://www.w3.org/2001/...

XSLT output to HTML

In my XSLT file, I have the following: <input type="button" value= <xsl:value-of select="name">> It s an error as it violates XML rule. What I actually want is having a value from an ...

Mangling IDs and References to IDs in XML

I m trying to compose xml elements into each other, and the problem I am having is when there s the same IDs. Basically what I need to do is mangle all the IDs in an xml file, as well as the ...

Sharepoint 2007 Data view Webpart custom parameters

I m sort of new to the custom parameters that can be setup on a DataView Webpart. There are 6 options: - None - Control - Cookie - Form - QueryString - Server Variable I think that None, Cookie and ...

热门标签