1

I am adding two xml files together using xslt, and then this resultant xml file should comply with a schema. I am able to add the two xml files together but then the result should have noNamespaceSchemaLocation="file:///osba.xsd" ass an attribute in the root element.

Here is my .xsl file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes" />
<xsl:variable name="with" select="'reception.xml'" />

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

<xsl:template match="bd">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()" />
  <xsl:variable name="info" select="document($with)/reception/bd[title=current()/title]/." />
  <xsl:for-each select="$info/*">
    <xsl:if test="name()!='title'">
      <xsl:copy-of select="." />
    </xsl:if>
  </xsl:for-each>
 </xsl:copy>
</xsl:template>
</xsl:transform>

I want to add something like:

<xsl:template match="/*" >
  <xsl:attribute name="noNamespaceSchemaLocation"><![CDATA[file:///I:/IMY%20Project/XML%20Files/osba.xsd]]></xsl:attribute>
<xsl:apply-templates/>                          

I have not found any way to match if the current element is root, I was also thinking of maybe putting an xsl:if test="root" type of deal in the first xsl:template.

Thanks for any help

1 Answer 1

1

Something like this:

    <xsl:template match="/*">
        <xsl:element name="{local-name(.)}" namespace="{namespace-uri(.)}">
            <xsl:copy-of select="@*"/>
            <xsl:attribute name="noNamespaceSchemaLocation"
                namespace="http://www.w3.org/2001/XMLSchema-instance">your-value</xsl:attribute>
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.