I am very new to XSLT , have a book and completed a few examples. However this is all for a small project. which takes a large XML file and outputs the XML omitting certain field. A sample of the XML is below.
Code:
<?xml version="1.0" encoding="windows-1252" ?>
<?xml-stylesheet type="text/xsl" href="testFIDEF.xsl"?>
<FileImport>
<Global>
<GlobalParam name="RollName" value="BUFVC003-14 10:00:00:00" />
<GlobalParam name="TapeOrg" value="10:00:00:00" />
<GlobalParam name="ReadStart" value="00:00:00:00" />
<GlobalParam name="ReadDuration" value="00:02:26:18" />
</Global>
<Roll>
<!-- roll contains lots of useless data that i don't want nor would it be helpful to you -->
<Field name="pd_roll_ingest_report" value="<?xml />
</Roll>
<MasterClip>
<Field name="audio_format" value="" group="Ingest" />
<Field name="camera_id" value="" group="Ingest" />
<Field name="clip_description" value="railway" group="Ingest" />
<Field name="clip_type" value="" group="Ingest" />
<Field name="clip_comments" value="" group="Ingest" />
</MasterClip>
</FileImport>
There are many more fields in MasterClip and the rest of the XML but these are the one ones i need to manage. I need to output only certain Field names in MasterClip eg the final XML transformation should look like.
Code:
<FileImport>
<Global>
<GlobalParam name="RollName" value="BUFVC003-08 10:00:00:00" />
<GlobalParam name="TapeOrg" value="10:00:00:00" />
<GlobalParam name="ReadStart" value="00:00:00:00" />
<GlobalParam name="ReadDuration" value="00:00:21:07" />
</Global>
<Roll>
</Roll>
<MasterClip>
<Field name="clip_description" value="railway " group="Ingest" />
<Field name="episode_no." value="BUFVC003-08" group="Ingest" />
<Field name="rushes_roll_number" value="BUFVC003" group="Ingest" />
<Field name="source_image_format" value="" group="Ingest" />
<Field name="technical_comments" value="MUTE" group="Ingest" />
</MasterClip>
</FileImport>
So I played around with the XSL and found a way to pick the ones I need.
Code:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="no" />
<xsl:variable name="fields" select="'|clip_description|episode_no|'" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="MasterClip">
<xsl:copy>
<xsl:apply-templates select=
"*[contains($fields, concat('|', @name, '|'))]" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
However this brings the "Rolls" tag with it in the output. I think this is because i am using @* instead of just dealing with searching inside MasterClip but i can not figure out how to handle the identity transformation. essentially I want Global - outputted the same as input , Roll with just opening and closing tags (no data) and then handle the MasterClip file "like" the above code.
Please help me, it seems easy enough doing one thing till i start trying to do something else on top :S.
The global tag i handled this way , if it helps:
Code:
<!--Global-->
<xsl:template match="Global">
<Global>
<xsl:apply-templates />
</Global>
</xsl:template>
<xsl:template match="GlobalParam">
<GlobalParam>
<xsl:attribute name="name">
<xsl:value-of select="@name" />
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="@value" />
</xsl:attribute>
</GlobalParam>
</xsl:template>
Any and all help very much appreciated.