XSLT:Muenchian多重分组困境



我有一个水疗服务列表,我需要通过XSLT 1.0通过分组将它们分解。我可以用分组来打破名字,但在我的子组中挣扎。如果您运行我的脚本,您会看到我的第一个Muenchian小组正常工作,将来宾名称明显地放置,但不确定为什么我的第二个串联键无法正常工作(日期)。谁能向我指向正确的方向?我不是很熟练XSLT,但我喜欢尝试!

简化输入

<SQLXMLExport>
<Rows>
<Row>
<Field alias="BOOK_FOR">Phone, Angie</Field>
<Field alias="START_DATE">Tuesday, December 5, 2017</Field>
<Field alias="ITEM_NAME">Sea Soak</Field>
</Row>
<Row>
<Field alias="BOOK_FOR">Phone, Angie</Field>
<Field alias="START_DATE">Tuesday, December 5, 2017</Field>
<Field alias="ITEM_NAME">Ocean Package - Weekday</Field>
</Row>
<Row>
<Field alias="BOOK_FOR">McNotes, Sue</Field>
<Field alias="START_DATE">Tuesday, December 5, 2017</Field>
<Field alias="ITEM_NAME">Experience Package - Weekday</Field>
</Row>
<Row>
<Field alias="BOOK_FOR">McNotes, Sue</Field>
<Field alias="START_DATE">Tuesday, December 5, 2017</Field>
<Field alias="ITEM_NAME">Morning Soak - Weekday</Field>
</Row>
<Row>
<Field alias="BOOK_FOR">McNotes, Sue</Field>
<Field alias="START_DATE">Wednesday, December 6, 2017</Field>
<Field alias="ITEM_NAME">Test Scrub - Weekday</Field>
</Row>
</Rows>
</SQLXMLExport>

我的XSLT 1.0

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:key name="guests" match="Rows/Row" use="./Field[@alias='BOOK_FOR']"/>
    <xsl:key name="guests-date" match="Rows/Row" use="concat( ./Field[@alias='BOOK_FOR'] , '|' , ./Field[@alias='START_DATE'] )"/>
        
    <xsl:template match="Rows">
        <!-- Now, we need to iterate on the guest key -->
        <xsl:for-each select="Row[count(. | key('guests', ./Field[@alias='BOOK_FOR'])[1]) = 1]">
            <!-- Sort by the guest -->
            <xsl:sort select="./Field[@alias='BOOK_FOR']" />
            <br/><xsl:value-of select="./Field[@alias='BOOK_FOR']" />
            <hr />
            <!-- Now loop on the items of this guest, we get them from the key we defined -->
            <xsl:for-each select="Row[count(. | key( 'guests-date' , concat(./Field[@alias='BOOK_FOR'] , '|' , ./Field[@alias='START_DATE'] ) )[1]) = 1]">
                <!-- Sort by the start date -->
                <!-- year  -->
                <xsl:sort select="substring-after(substring-after(./Field[@alias='START_DATE'],','), ',')" order="ascending" data-type="number" />
                <!-- day  -->
                <xsl:sort select="substring-after(substring-after(substring-before(substring-after(./Field[@alias='START_DATE'],','), ','), ' '), ' ' )" order="ascending" data-type="number" />
                 <!-- month...this is a mess, tackle later
                <xsl:sort select="substring-before(substring-after(./Field[@alias='START_DATE'],','), ' ')" order="ascending" data-type="number" />
                -->
                <xsl:value-of select="./Field[@alias='START_DATE']" /><br/>           
                <xsl:value-of select="./Field[@alias='ITEM_NAME']" /><br/>
            </xsl:for-each>
            <br />
        </xsl:for-each>
    </xsl:template>
      
</xsl:stylesheet>

所需的输出

我想将其放在名称首先的位置,然后在每个名称下是他们来的日子,每个日期都列出了他们的服务。如下所示:

McNotes, Sue
<hr>
<b>Tuesday, December 5, 2017</b><br>
Experience Package - Weekday<br>
Morning Soak - Weekday<br>
<b>Wednesday, December 6, 2017</b>
Test Scrub - Weekday<br>
Phone, Angie
<hr>
<b>Tuesday, December 5, 2017</b><br>
Sea Soak<br>
Ocean Package - Weekday<br>

更改以下内容:

<xsl:for-each select="Row[count(. | key( 'guests-date' , concat(./Field[@alias='BOOK_FOR'] , '|' , ./Field[@alias='START_DATE'] ) )[1]) = 1]">

to:

<xsl:for-each select="../Row[count(. | key( 'guests-date' , concat(./Field[@alias='BOOK_FOR'] , '|' , ./Field[@alias='START_DATE'] ) )[1]) = 1]">

说明

您处于Row的上下文中;您需要上升到父 Rows,以便在同一组中选择兄弟姐妹 Row s。

相关内容

  • 没有找到相关文章

最新更新