Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 51 by
met...@sarangbang.or.kr: a way to specify expected
attributes for templates which "yields attributes"
http://code.google.com/p/xspec/issues/detail?id=51
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.