How to read input file from global parameter, modify and send it to output? [XSLT]

what should I write inside the template "initial" to read file from input, modify few nodes from input and send that modified file to output?

Here is a sample:

<?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:xs="http://www.w3.org/2001/XMLSchema"
       exclude-result-prefixes="xs" xmlns:saxon="http://saxon.sf.net/" 
       extension-element-prefixes="saxon"
       version="2.0">

        <xsl:output method="xml" indent="yes" media-type="text/xml" />
        <xsl:param name="$input_file"/>
        <xsl:param name="input" select="saxon:parse($input_file)"></xsl:param>

        <xsl:template match="/" name="initial">
            <xsl:result-document href="output.xml">

            </xsl:result-document>


        </xsl:template>

    </xsl:stylesheet>

Answers


Simply write the templates that perform the transformation changes you want to make and apply-templates to all parsed nodes:

    <xsl:output method="xml" indent="yes" media-type="text/xml" />

    <xsl:param name="input_xml" as="xs:string"><![CDATA[<root>
      <foo>foo 1</foo>
      <bar>bar 1</bar>
    </root>]]></xsl:param>

    <xsl:param name="input" select="saxon:parse($input_xml)"/>

    <xsl:template match="/" name="initial">

           <xsl:apply-templates select="$input/node()"/>

    </xsl:template>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="bar">
        <foobar>
            <xsl:apply-templates select="@* | node()"/>
        </foobar>
    </xsl:template>

</xsl:stylesheet>

If you want a particular output document then wrap the apply-templates e.g.

    <xsl:output method="xml" indent="yes" media-type="text/xml" />

    <xsl:param name="input_xml" as="xs:string"><![CDATA[<root>
      <foo>foo 1</foo>
      <bar>bar 1</bar>
    </root>]]></xsl:param>

    <xsl:param name="input" select="saxon:parse($input_xml)"/>

    <xsl:template match="/" name="initial">
        <xsl:result-document href="output.xml">
           <xsl:apply-templates select="$input/node()"/>
        </xsl:result-document>
    </xsl:template>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="bar">
        <foobar>
            <xsl:apply-templates select="@* | node()"/>
        </foobar>
    </xsl:template>

</xsl:stylesheet>

Need Your Help

Combine duplicate hash keys in ruby

ruby json hash

I am attempting to take JSON like this:

how can I correct my code to make this AppBarButton stretshes in the CommandBar

xaml uwp win-universal-app uwp-xaml

I am trying to stretch the AppBarButton in my SecondaryCommands with this Style: