Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoogleCodeExporter opened this issue Jun 8, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 15 Sep 2012 at 8:11

@GoogleCodeExporter
Copy link
Author

Oops, the template S1->T2 (the one before the refactoring) is duplicated. Sorry 
for the mess.

Original comment by [email protected] on 15 Sep 2012 at 8:14

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

No branches or pull requests

1 participant