Changing an XML document using XSL transformations - Part II

webmasterbeta

New Member
Hi, sincerest thanks to Russell Jones for his help. His suggestion does afantastic job of promoting the "Sub-Shot" nodes replacing the parent nodeas necessary. I'm trying to get the template to work alongside another (mutuallyexclusive) template which looks after the functionality for the "EXACT COPY"of the other nodes from the original xml document. I cannot get the codeto apply Russell's template when necessary. Any suggestions as to what I'mdoing wrong, or an elegant solution?<xsl:template match="/"><xsl:choose><xsl:when test="name()='Shot'"><xsl:apply-templates select="node()" mode="process_shots"/></xsl:when><xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise></xsl:choose></xsl:template><xsl:template match="Shot" mode="process_shots"><xsl:choose><xsl:when test="count(child::Shot) > 0"><xsl:copy-of select="child::Shot"/></xsl:when><xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise></xsl:choose></xsl:template>Best regards,ADK.>> Hi. I have an XML document that I want to perform an XSL transformationon>> and I'm not sure how to get the results I want. Let me give an exampleof>> the original and desired documents.>>>> Original XML:>> <Material_Description Material_ID="MyVideo">>> <Volume Material_ID="MyVideo">>> <Label>MyVideoFootage</Label>>> <Shot Material_ID="Shot1">>> <In_Frame />>> <Out_Frame />>>>> <Shot Material_ID="SubShot1a">>> <In_Frame />>> <Out_Frame />>> </Shot>>>>> <Shot Material_ID="SubShot1b">>> <In_Frame />>> <Out_Frame />>> </Shot>>> </Shot>>> <Shot Material_ID="Shot2">>> <In_Frame />>> <Out_Frame />>> </Shot>>> <Volume>>> </Material_Description>>>>> I'd like to use an XSL transformation to create an EXACT COPY of the>original>> XML document plus a modification in the XML node hierarchy so that ifa>"SubShot">> exists, it replaces its "Shot" parent node.>>>> Desired XML:>> <Material_Description Material_ID="MyVideo">>> <Volume Material_ID="MyVideo">>> <Label>MyVideoFootage</Label>>> <Shot Material_ID="SubShot1a">>> <In_Frame />>> <Out_Frame />>> </Shot>>> <Shot Material_ID="SubShot1b">>> <In_Frame />>> <Out_Frame />>> </Shot>>> <Shot Material_ID="Shot2">>> <In_Frame />>> <Out_Frame />>> </Shot>>> <Volume>>> </Material_Description>>>>> Everything I read about XSL transformations indicates that this shouldbe>> possible, but I can't work out the syntax to achieve the desired result.>> I believe I could solve this using a DOM, but I'm very new to XSL andI>> suspect the XSL solution would be more elegant and extensible. Humble>cries>> for help from an XSL rookie.>>>> Best regards,>>>> ADK.
 
Back
Top