EDN Admin
Well-known member
i am looking to get only one of the subset xml tags from the given input xml file. I need a xslt tranform program to take input as given below and give out based on the transform name given. Here is my input format , output format and xslt program
which i wrote but not getting required output. Here its giving all basetranformname sub elements values but not overriding sub transform child elements.
Input:
<transform name="FlashToAVI <br/>
<acceptanceCriteria><br/>
<criteria attName="ContainerFormat" op="Must-match" value="Flash video" />
<br/>
<criteria attName="CompressionFormat" op="must-match" value="H.264" />
<br/>
<criteria attName="Duration" op="greaterThan" value="0" /> <br/>
<criteria attName="AudioContainerFormat" op="One-of" value="WAV , WAVE" />
<br/>
<criteria attName="AudioCompressionFormat" op="One-of" value="MPEG-1 , MPEG-2, GSM-FR" />
<br/>
</acceptanceCriteria><br/>
<forcingFunction Transformname="AVIbasic <br/>
<ContainerFormat>AVI</ContainerFormat><br/>
<CompressionFormat>Uncompressed(RGB)</CompressionFormat><br/>
<fileExtension>.avi</fileExtension><br/>
<MaxWidth>320</MaxWidth> <br/>
<MaxHeight>240</MaxHeight><br/>
<VideoBitrate>1000</VideoBitrate><br/>
<Framerate>15</Framerate><br/>
<PixalAspectRatio>Video 4:3 and Pixel 1:1</PixalAspectRatio><br/>
<AudioFormat>Use Existing</AudioFormat><br/>
<AudioCompressionFormat>MP3(Rhozet MP3 Encoder)</AudioCompressionFormat><br/>
<AudioBitrate>48</AudioBitrate><br/>
<AudioBitSampleSize>128</AudioBitSampleSize>28" />
<br/>
</forcingFunction><br/>
<forcingFunction Transformname="CanopusDVAVI1NTSC" baseTransformname="AVIbasic <br/>
<CompressionFormat>CanopusDv</CompressionFormat><br/>
<PixalAspectRatio>Video 4:3 and Pixel 9:10</PixalAspectRatio><br/>
<AudioFormat>Use Existing</AudioFormat><br/>
<AudioCompressionFormat>Linear PCM</AudioCompressionFormat><br/>
<AudioBitrate>44.1</AudioBitrate><br/>
<AudioBitSampleSize>16</AudioBitSampleSize><br/>
</forcingFunction><br/>
<forcingFunction Transformname="CanopusDVAVI1NTSCWideScreen" baseTransformname="CanopusDVAVI1NTSC <br/>
<CompressionFormat>CopusDv</CompressionFormat><br/>
</forcingFunction><br/>
</transform><br/>
<br/>
<br/>
Output:<br/>
<br/>
<transform name="FlashToAVI <br/>
<acceptanceCriteria><br/>
<criteria attName="ContainerFormat" op="Must-match" value="Flash video" /><br/>
<criteria attName="CompressionFormat" op="must-match" value="H.264" /><br/>
<criteria attName="Duration" op="greaterThan" value="0" /><br/>
<criteria attName="AudioContainerFormat" op="One-of" value="WAV , WAVE" /><br/>
<criteria attName="AudioCompressionFormat" op="One-of" value="MPEG-1 , MPEG-2, GSM-FR" /><br/>
</acceptanceCriteria><br/>
<forcingFunction Transformname="CanopusDVAVI1NTSC <br/>
<ContainerFormat>AVI</ContainerFormat><br/>
<CompressionFormat>Uncompressed(RGB)</CompressionFormat><br/>
<fileExtension>.avi</fileExtension><br/>
<MaxWidth>320</MaxWidth><br/>
<MaxHeight>240</MaxHeight><br/>
<VideoBitrate>1000</VideoBitrate><br/>
<Framerate>15</Framerate><br/>
<PixalAspectRatio>Video 4:3 and Pixel 9:10</PixalAspectRatio><br/>
<AudioFormat>Use Existing</AudioFormat><br/>
<AudioCompressionFormat>Linear PCM</AudioCompressionFormat><br/>
<AudioBitrate>44.1</AudioBitrate><br/>
<AudioBitSampleSize>16</AudioBitSampleSize><br/>
</forcingFunction><br/>
</transform><br/>
<br/>
<br/>
My xslt program:
<?xml version="1.0" encoding="UTF-8"?><br/>
<xsl:stylesheet version="1.0"<br/>
xmlns:xsl="http://www.w3.org/1999/XSL/Transform <br/>
<xslutput media-type="text/xml"/><br/>
<br/>
<xslaram name="criteria" select="CanopusDVAVI1NTSCWideScreen"/><br/>
<br/>
<xslaram name="baset" select="//forcingFunction[@Transformname=$criteria]/@baseTransformname"/><br/>
<br/>
<xslaram name="baset1" select="//forcingFunction[@Transformname=$baset]/@baseTransformname"/><br/>
<br/>
<xsl:template match="/ <br/>
<br/>
<xsl:element name="transform <br/>
<br/>
<xsl:attribute name="name <br/>
<br/>
<xsl:value-of select="FlashToAVI"/><br/>
<br/>
</xsl:attribute><br/>
<br/>
<xsl:apply-templates select="transform[@name]/acceptanceCriteria"/><br/>
<br/>
<xsl:apply-templates select="//forcingFunction[@Transformname=$baset1]"/>
<br/>
<br/>
</xsl:element><br/>
<br/>
</xsl:template><br/>
<br/>
<xsl:template match="node()|@* <br/>
<br/>
<xsl:copy><br/>
<br/>
<xsl:apply-templates select="@*|node()"/><br/>
<br/>
</xsl:copy><br/>
<br/>
</xsl:template><br/>
<br/>
</xsl:stylesheet><br/>
<br/>
<br/>
View the full article
which i wrote but not getting required output. Here its giving all basetranformname sub elements values but not overriding sub transform child elements.
Input:
<transform name="FlashToAVI <br/>
<acceptanceCriteria><br/>
<criteria attName="ContainerFormat" op="Must-match" value="Flash video" />
<br/>
<criteria attName="CompressionFormat" op="must-match" value="H.264" />
<br/>
<criteria attName="Duration" op="greaterThan" value="0" /> <br/>
<criteria attName="AudioContainerFormat" op="One-of" value="WAV , WAVE" />
<br/>
<criteria attName="AudioCompressionFormat" op="One-of" value="MPEG-1 , MPEG-2, GSM-FR" />
<br/>
</acceptanceCriteria><br/>
<forcingFunction Transformname="AVIbasic <br/>
<ContainerFormat>AVI</ContainerFormat><br/>
<CompressionFormat>Uncompressed(RGB)</CompressionFormat><br/>
<fileExtension>.avi</fileExtension><br/>
<MaxWidth>320</MaxWidth> <br/>
<MaxHeight>240</MaxHeight><br/>
<VideoBitrate>1000</VideoBitrate><br/>
<Framerate>15</Framerate><br/>
<PixalAspectRatio>Video 4:3 and Pixel 1:1</PixalAspectRatio><br/>
<AudioFormat>Use Existing</AudioFormat><br/>
<AudioCompressionFormat>MP3(Rhozet MP3 Encoder)</AudioCompressionFormat><br/>
<AudioBitrate>48</AudioBitrate><br/>
<AudioBitSampleSize>128</AudioBitSampleSize>28" />
<br/>
</forcingFunction><br/>
<forcingFunction Transformname="CanopusDVAVI1NTSC" baseTransformname="AVIbasic <br/>
<CompressionFormat>CanopusDv</CompressionFormat><br/>
<PixalAspectRatio>Video 4:3 and Pixel 9:10</PixalAspectRatio><br/>
<AudioFormat>Use Existing</AudioFormat><br/>
<AudioCompressionFormat>Linear PCM</AudioCompressionFormat><br/>
<AudioBitrate>44.1</AudioBitrate><br/>
<AudioBitSampleSize>16</AudioBitSampleSize><br/>
</forcingFunction><br/>
<forcingFunction Transformname="CanopusDVAVI1NTSCWideScreen" baseTransformname="CanopusDVAVI1NTSC <br/>
<CompressionFormat>CopusDv</CompressionFormat><br/>
</forcingFunction><br/>
</transform><br/>
<br/>
<br/>
Output:<br/>
<br/>
<transform name="FlashToAVI <br/>
<acceptanceCriteria><br/>
<criteria attName="ContainerFormat" op="Must-match" value="Flash video" /><br/>
<criteria attName="CompressionFormat" op="must-match" value="H.264" /><br/>
<criteria attName="Duration" op="greaterThan" value="0" /><br/>
<criteria attName="AudioContainerFormat" op="One-of" value="WAV , WAVE" /><br/>
<criteria attName="AudioCompressionFormat" op="One-of" value="MPEG-1 , MPEG-2, GSM-FR" /><br/>
</acceptanceCriteria><br/>
<forcingFunction Transformname="CanopusDVAVI1NTSC <br/>
<ContainerFormat>AVI</ContainerFormat><br/>
<CompressionFormat>Uncompressed(RGB)</CompressionFormat><br/>
<fileExtension>.avi</fileExtension><br/>
<MaxWidth>320</MaxWidth><br/>
<MaxHeight>240</MaxHeight><br/>
<VideoBitrate>1000</VideoBitrate><br/>
<Framerate>15</Framerate><br/>
<PixalAspectRatio>Video 4:3 and Pixel 9:10</PixalAspectRatio><br/>
<AudioFormat>Use Existing</AudioFormat><br/>
<AudioCompressionFormat>Linear PCM</AudioCompressionFormat><br/>
<AudioBitrate>44.1</AudioBitrate><br/>
<AudioBitSampleSize>16</AudioBitSampleSize><br/>
</forcingFunction><br/>
</transform><br/>
<br/>
<br/>
My xslt program:
<?xml version="1.0" encoding="UTF-8"?><br/>
<xsl:stylesheet version="1.0"<br/>
xmlns:xsl="http://www.w3.org/1999/XSL/Transform <br/>
<xslutput media-type="text/xml"/><br/>
<br/>
<xslaram name="criteria" select="CanopusDVAVI1NTSCWideScreen"/><br/>
<br/>
<xslaram name="baset" select="//forcingFunction[@Transformname=$criteria]/@baseTransformname"/><br/>
<br/>
<xslaram name="baset1" select="//forcingFunction[@Transformname=$baset]/@baseTransformname"/><br/>
<br/>
<xsl:template match="/ <br/>
<br/>
<xsl:element name="transform <br/>
<br/>
<xsl:attribute name="name <br/>
<br/>
<xsl:value-of select="FlashToAVI"/><br/>
<br/>
</xsl:attribute><br/>
<br/>
<xsl:apply-templates select="transform[@name]/acceptanceCriteria"/><br/>
<br/>
<xsl:apply-templates select="//forcingFunction[@Transformname=$baset1]"/>
<br/>
<br/>
</xsl:element><br/>
<br/>
</xsl:template><br/>
<br/>
<xsl:template match="node()|@* <br/>
<br/>
<xsl:copy><br/>
<br/>
<xsl:apply-templates select="@*|node()"/><br/>
<br/>
</xsl:copy><br/>
<br/>
</xsl:template><br/>
<br/>
</xsl:stylesheet><br/>
<br/>
<br/>
View the full article