How to test XSLT having multiple mode with XSpec?
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 1
- Joined: Sat Dec 24, 2022 6:27 pm
How to test XSLT having multiple mode with XSpec?
Need to write XSpec test case to test the XSLT, in which multiple modes are used for transformation. But with below test-case, the xspec only tests the output with default mode applied. I wonder if there is a way to test the final output of the transformation.
film plus bee tv
Need to write XSpec test case to test the XSLT, in which multiple modes are used for transformation. But with below test-case, the xspec only tests the output with default mode applied. I wonder if there is a way to test the final output of the transformation.
O\P for first <p>:
-- after default mode applied: <p class="Title" text-align="center">. [below xspec tests this o\p]
-- final: <title text-align="center">. [Want to test this o\p]
Any suggestion in this regard would be a great help. Thanks...
film plus bee tv
Code: Select all
<!-- input.xml -->
<body>
<div>
<p class="Title"><span>My first title</span></p>
<p class="BodyText"><span style="font-weight:bold">AAAAAAA</span><span>2 Jan 2020</span></p>
</div>
</body>
Code: Select all
<!-- conv.xsl -->
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<!-- default mode : adding text-align attribute where @class=Title -->
<xsl:template match="*[ancestor::body]">
<xsl:choose>
<xsl:when test="@class = 'Title'">
<xsl:element name="{local-name()}">
<xsl:copy-of select="@* except @style"/>
<xsl:attribute name="text-align" select="'center'"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- bodytext mode : changing element name to <title> where p[@class=Title] -->
<xsl:template match="p[@class]" mode="bodytext">
<xsl:choose>
<xsl:when test="@class = 'Title'">
<title>
<xsl:copy-of select="@* except @class"/>
<xsl:apply-templates mode="bodytext"/>
</title>
</xsl:when>
<xsl:otherwise>
<para>
<xsl:apply-templates mode="bodytext"/>
</para>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="body">
<xsl:variable name="data">
<body>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</body>
</xsl:variable>
<xsl:apply-templates select="$data" mode="bodytext"/>
</xsl:template>
<xsl:template match="node() | @*" mode="#all">
<xsl:copy>
<xsl:apply-templates select="node() | @*" mode="#current"/>
</xsl:copy>
</xsl:template>
Need to write XSpec test case to test the XSLT, in which multiple modes are used for transformation. But with below test-case, the xspec only tests the output with default mode applied. I wonder if there is a way to test the final output of the transformation.
Code: Select all
<!-- input.xml -->
<body>
<div>
<p class="Title"><span>My first title</span></p>
<p class="BodyText"><span style="font-weight:bold">AAAAAAA</span><span>2 Jan 2020</span></p>
</div>
</body>
<!-- conv.xsl -->
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<!-- default mode : adding text-align attribute where @class=Title -->
<xsl:template match="*[ancestor::body]">
<xsl:choose>
<xsl:when test="@class = 'Title'">
<xsl:element name="{local-name()}">
<xsl:copy-of select="@* except @style"/>
<xsl:attribute name="text-align" select="'center'"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- bodytext mode : changing element name to <title> where p[@class=Title] -->
<xsl:template match="p[@class]" mode="bodytext">
<xsl:choose>
<xsl:when test="@class = 'Title'">
<title>
<xsl:copy-of select="@* except @class"/>
<xsl:apply-templates mode="bodytext"/>
</title>
</xsl:when>
<xsl:otherwise>
<para>
<xsl:apply-templates mode="bodytext"/>
</para>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="body">
<xsl:variable name="data">
<body>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</body>
</xsl:variable>
<xsl:apply-templates select="$data" mode="bodytext"/>
</xsl:template>
<xsl:template match="node() | @*" mode="#all">
<xsl:copy>
<xsl:apply-templates select="node() | @*" mode="#current"/>
</xsl:copy>
</xsl:template>
-- after default mode applied: <p class="Title" text-align="center">. [below xspec tests this o\p]
-- final: <title text-align="center">. [Want to test this o\p]
Code: Select all
Need to write XSpec test case to test the XSLT, in which multiple modes are used for transformation. But with below test-case, the xspec only tests the output with default mode applied. I wonder if there is a way to test the final output of the transformation.
<!-- input.xml -->
<body>
<div>
<p class="Title"><span>My first title</span></p>
<p class="BodyText"><span style="font-weight:bold">AAAAAAA</span><span>2 Jan 2020</span></p>
</div>
</body>
<!-- conv.xsl -->
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<!-- default mode : adding text-align attribute where @class=Title -->
<xsl:template match="*[ancestor::body]">
<xsl:choose>
<xsl:when test="@class = 'Title'">
<xsl:element name="{local-name()}">
<xsl:copy-of select="@* except @style"/>
<xsl:attribute name="text-align" select="'center'"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- bodytext mode : changing element name to <title> where p[@class=Title] -->
<xsl:template match="p[@class]" mode="bodytext">
<xsl:choose>
<xsl:when test="@class = 'Title'">
<title>
<xsl:copy-of select="@* except @class"/>
<xsl:apply-templates mode="bodytext"/>
</title>
</xsl:when>
<xsl:otherwise>
<para>
<xsl:apply-templates mode="bodytext"/>
</para>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="body">
<xsl:variable name="data">
<body>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</body>
</xsl:variable>
<xsl:apply-templates select="$data" mode="bodytext"/>
</xsl:template>
<xsl:template match="node() | @*" mode="#all">
<xsl:copy>
<xsl:apply-templates select="node() | @*" mode="#current"/>
</xsl:copy>
</xsl:template>
O\P for first <p>:
-- after default mode applied: <p class="Title" text-align="center">. [below xspec tests this o\p]
-- final: <title text-align="center">. [Want to test this o\p]
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: How to test XSLT having multiple mode with XSpec?
Post by alex_jitianu »
Hi,
It looks like you've pasted the XSLT instead of the XSpec scenario in the original post. Anyway, you can specify the mode explicitly when you write the scenario:
This might be what you need.
Best regards,
Alex
It looks like you've pasted the XSLT instead of the XSpec scenario in the original post. Anyway, you can specify the mode explicitly when you write the scenario:
Code: Select all
<x:scenario label="when processing a para element in 'shortdesc' mode">
<x:context mode="shortdesc">
<para>...</para>
</x:context>
...
</x:scenario>
Best regards,
Alex
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service