Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

a way to specify expected attributes for templates which "yields attributes" #51

Open

Description

@GoogleCodeExporter
Is there a way to test templates which yield attributes? i.e.,

<xsl:template select="src-element" mode="attr-group-1">
  <xsl:attribute name="a">...</xsl:attribute>
  <xsl:attribute name="b">...</xsl:attribute>
</xsl:template>

<xsl:template select="src-element" mode="attr-group-2">
  <xsl:attribute name="c">...</xsl:attribute>
  <xsl:attribute name="d">...</xsl:attribute>
</xsl:template>

<scenario>
  <context mode="attr-group-1">
    <src-element ... />
  </context>
  <expect>
    <!-- ??? specify expected attributes -->
   </expect>
</scenario>


Here's some backgrounds:

I have many templates yield common set of attributes for different elements 
(from different source elements), i.e.,

<template match="S1" mode="T1">
  <element name="T1">
    <attribute name="common-a"><value-of select="@s1-a"></attribute>
    <attribute name="common-b"><value-of select="@s1-b"></attribute>
    <attribute name="t1">...</attribute>
  </element>
</template>

<template match="S1" mode="T2">
  <element name="T2">
    <attribute name="common-a"><value-of select="@s1-a"></attribute>
    <attribute name="common-b"><value-of select="@s1-b"></attribute>
    <attribute name="t2">...</attribute>
  </element>
</template>

<template match="S2" mode="T1">
  <element name="T1">
    <attribute name="common-a"><value-of select="@s2-a"></attribute>
    <attribute name="common-b"><value-of select="@s2-b"></attribute>
    <attribute name="t1">...</attribute>
  </element>
</template>

<template match="S1" mode="T2">
  <element name="T2">
    <attribute name="common-a"><value-of select="@s1-a"></attribute>
    <attribute name="common-b"><value-of select="@s1-b"></attribute>
    <attribute name="t2">...</attribute>
  </element>
</template>

<template match="S2" mode="T2">
  <element name="T2">
    <attribute name="common-a"><value-of select="@s2-a"></attribute>
    <attribute name="common-b"><value-of select="@s2-b"></attribute>
    <attribute name="t2">...</attribute>
  </element>
</template>

There are so many duplications, so I want to refactor these templates as like 
following:

<!-- common attributes -->
<template match="S1" mode="common-attrs">
  <attribute name="common-a"><value-of select="@s1-a"></attribute>
  <attribute name="common-b"><value-of select="@s1-b"></attribute>
</template>

<template match="S2" mode="common-attrs">
  <attribute name="common-a"><value-of select="@s2-a"></attribute>
  <attribute name="common-b"><value-of select="@s2-b"></attribute>
</template>

<!-- each transforms of {S1,S2} x {T1, T2} -->
<template match="S1" mode="T1">
  <element name="T1">
    <apply-templates select="." mode="common-attrs" />
    <attribute name="t1">...</attribute>
  </element>
</template>

<template match="S1" mode="T2">
  <element name="T2">
    <apply-templates select="." mode="common-attrs" />
    <attribute name="t2">...</attribute>
  </element>
</template>

<template match="S2" mode="T1">
  <element name="T1">
    <apply-templates select="." mode="common-attrs" />
    <attribute name="t1">...</attribute>
  </element>
</template>

<template match="S2" mode="T2">
  <element name="T2">
    <apply-templates select="." mode="common-attrs" />
    <attribute name="t2">...</attribute>
  </element>
</template>

So it would be great there is some ways to test the "common-attrs" templates.

Original issue reported on code.google.com by met...@sarangbang.or.kr on 15 Sep 2012 at 8:11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions