Muenchian分组-根据行数显示第二级 [英] Muenchian Grouping - display second level base on row count

查看:93
本文介绍了Muenchian分组-根据行数显示第二级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上一篇文章的Tim的帮助下,我能够使Muenchian分组适用于我的测试xml/xsl.但是在使用我的实际xml时,我遇到了以下另一种情况.输入xml看起来很简单,为简化起见.如您所见,<name>Status</name> <value>Existing</value>在实际xml中还有许多其他条目.

With help of Tim from my previous post, i was able to get the Muenchian grouping working for my test xml/xsl. But while working with my actual xml i encountered a different scenario as below. The input xml looks like, reduced it for simplicity. As you see the <name>Status</name> <value>Existing</value> there are many other entries in actual xml.

<message>
<requisition>
<data-values>
    <data-value multi-valued="false">
        <name>Test_Grid-1.Name</name> <value>1</value>
    </data-value>
    <data-value multi-valued="false">
        <name>Test_Grid-1.SupportType</name> <value>Monthly,Quarterly</value>
    </data-value>
    <data-value multi-valued="false">
        <name>Test_Grid-2.Name</name> <value>2</value>
    </data-value>
    <data-value multi-valued="false">
        <name>Test_Grid-2.SupportType</name> <value>Monthly</value>
    </data-value>
    <data-value multi-valued="false">
        <name>Status</name> <value>Existing</value>
    </data-value>
</data-values>
</requisition>
<agent-parameter multi-valued="false">
  <name>ActionType</name> <value>New</value>
</agent-parameter>
<agent-parameter multi-valued="false">
  <name>Dictionary</name> <value>Test_Grid</value>
</agent-parameter>
<agent-parameter multi-valued="false">
  <name>ActionName</name> <value>SupportData</value>
</agent-parameter>
</message>

我正在使用的XSL是:

The XSL i am using is:

<xsl:key name="record" match="data-value" use="substring-before(name, '.')" />

<xsl:template match="message">
  <record>
    <xsl:apply-templates select="//data-value[generate-id() = generate-id(key('record', substring-before(name, '.'))[1])]" mode="record" />
  </record>
</xsl:template>
<xsl:template match="data-value" mode="record">
<rowData>
  <name><xsl:value-of select="$ServiceItemName" /></name>
 <xsl:apply-templates select="key('record', substring-before(name, '.'))" />
</rowData>
</xsl:template>

<xsl:template match="data-value">
 <xsl:if test="starts-with(name,concat($Dictionary,'-'))">
   <rowAttribute name="{substring-after(name, '.')}"><xsl:value-of select="value" />   </rowAttribute>
 </xsl:if>
</xsl:template>

实际的输入xml包含不同的数据值(Test_Grid-1或Test_Grid-2等除外).在那种情况下,xsl正在拉动所有这些元素并显示在内部.有什么办法可以过滤仅以"Test_Grid-"开头的值(我的代理参数名称为Dictionary且值为"Test_Grid"),并且xsl仅提取那些以名称开头的数据值-使用concat($Dictionary,'-').我尝试了以下

The actual input xml contains different data-values (other than Test_Grid-1 or Test_Grid-2 etc). In that scenario the xsl is pulling all those elements and showing inside . Is there any way i can filter the values only starting with "Test_Grid-" (i have the agent-parameter with name Dictionary and value as "Test_Grid") and the xsl will pull only those data-values where the name starts-with concat($Dictionary,'-'). I tried something like below

       <xsl:template match="data-value">
    <xsl:if test="starts-with(name,concat($Dictionary,'-'))">
        <rowAttribute name="{substring-after(name, '.')}"><xsl:value-of select="value" /></rowAttribute>
    </xsl:if>

但是它在输出中显示了空白元素,如下所示,并显示了所需的输出.

But its showing empty elements in output like below along with the required output.

 <record>
            <name>SupportData</ext:name>
 </record>
 <record>
              <name>SupportData</name>
    <rowData>
              <rowAttribute name="Name">Record1</rowAttribute>
              <rowAttribute name="SupportType">Quarterly</rowAttribute>
    </rowData>        
 </record>

有没有一种方法可以仅在元素中包含一些rowData元素时显示该元素.

Is there a way i can show the element only when it has some rowData elements in it.

我们将不胜感激.

推荐答案

要忽略名称不以'Test_Grid-开头的 data-value 元素,可以使用xpath函数'starts-with '.您可以在xpath表达式中添加条件以过滤数据值元素

To ignore data-value elements whose name do not start with 'Test_Grid-' you can use the xpath function 'starts-with'. You can add a condition to the xpath expression to filter the data-value elements

data-value[starts-with(name, 'Test_Grid-')]

您实际上可以将其添加到数据值上的 xsl:key 匹配中,或添加到您在其中的 xsl:apply-templates 选择它们.例如,您可以执行以下操作:

You can actually add this to the xsl:key match on data-value, or to the xsl:apply-templates where you select them. For example, you could either do this:

<xsl:key name="record" match="data-value[starts-with(name, 'Test_Grid-')]" use="substring-before(name, '.')" />

或者,您也可以这样做

<xsl:apply-templates 
    select="requisition/data-values/data-value
       [starts-with(name, 'Test_Grid-')]
       [generate-id() = generate-id(key('record', substring-before(name, '.'))[1])]" 
    mode="record" />

将其作为密钥的一部分可能会更有效.通过将其作为键的一部分,对不同元素的检查将仅考虑以'Test-Grid-'开头的元素.

It may be more efficient to put it as part of the key. By putting it as part of the key, the check for distinct elements will only consider ones beginning with 'Test-Grid-'.

这篇关于Muenchian分组-根据行数显示第二级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆