Reputation: 4145
I have the following XSL, which I use to transform Oracle SQL developer's XML format to the "full" XML format expected by DBUnit (for creating data sets for testing).
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="java"
xmlns:dbutil="com.jason.util.DatabaseTestUtil">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:text disable-output-escaping="yes"><dataset></xsl:text>
<xsl:text>
</xsl:text>
<xsl:text disable-output-escaping="yes"><table name=""></xsl:text>
<xsl:text>
</xsl:text>
<xsl:for-each select="RESULTS/ROW">
<xsl:for-each select="COLUMN">
<xsl:text disable-output-escaping="yes"><column></xsl:text>
<xsl:value-of select="@NAME" />
<xsl:text disable-output-escaping="yes"></column></xsl:text>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:for-each>
<xsl:for-each select="RESULTS">
<xsl:for-each select="ROW">
<xsl:text disable-output-escaping="yes"><row></xsl:text>
<xsl:for-each select="COLUMN">
<xsl:text disable-output-escaping="yes"><value descriptor="</xsl:text>
<xsl:value-of select="@NAME"/>
<xsl:text disable-output-escaping="yes">"></xsl:text>
<xsl:choose>
<xsl:when test="@NAME='NAME'">
<xsl:value-of select="dbutil:generateRandomName()" />
</xsl:when>
<xsl:when test="@NAME='MEMBER_SSN'">
<xsl:value-of select="dbutil:generateRandomSsn()" />
</xsl:when>
<xsl:when test="@NAME='SPOUSE_SSN'">
<xsl:variable name="spouseSsn">
<xsl:value-of select="." />
</xsl:variable>
<xsl:if test="dbutil:hasSpouseSsn($spouseSsn)"><xsl:value-of select="dbutil:generateRandomSsn()" /></xsl:if>
</xsl:when>
<xsl:when test="@NAME=E_MAIL_ADDRESS">
<xsl:text>[email protected]</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="." />
</xsl:otherwise>
</xsl:choose>
<xsl:text disable-output-escaping="yes"></value></xsl:text>
<xsl:text>
</xsl:text>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:text disable-output-escaping="yes"></row></xsl:text>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:for-each>
<xsl:text disable-output-escaping="yes"></table></xsl:text>
<xsl:text>
</xsl:text>
<xsl:text disable-output-escaping="yes"></dataset></xsl:text>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
I have a call to some "backend" java so that I don't have people's private information embedded in my test sets.
Unfortunately, the first loop through /RESULTS/ROW should only be a loop through the columns of the first child of /RESULT/ROW.
Can anyone tell me how to get that first child?
Upvotes: 1
Views: 4119
Reputation: 243549
Unfortunately, the first loop through /RESULTS/ROW should only be a loop through the columns of the first child of /RESULT/ROW.
Can anyone tell me how to get that first child?
Replace:
<xsl:for-each select="RESULTS/ROW">
<xsl:for-each select="COLUMN">
. . . . . . . . .
</xsl:for-each>
</xsl:for-each>
with:
<xsl:for-each select="RESULTS/ROW[1]/Column">
. . . . . . . . .
</xsl:for-each>
Upvotes: 2