Rectangle 27 2

If you're creating the mgh:message as a literal result element then provided those namespace declarations are in scope at the appropriate place it should just work:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:prism="http://prismstandard.org/namespaces/basic/2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1"
    xmlns:prl="http://prismstandard.org/namespaces/prl/2.0"
    xmlns:mgh="http://comp.com/prismPlus-XSD">

  <xsl:template match="/">
    <mgh:message xsi:schemaLocation="http://comp.com/prismPlus-XSD HeardsContent.xsd">
      <!-- etc -->

since literal result elements preserve the namespaces that are in scope at that point in the stylesheet.

You could of course just put the declarations on the mgh:message element itself rather than on the xsl:stylesheet, but then if you're creating the dc:* elements in another template you'd have to repeat the xmlns:dc there as well. Overall, I find it easier to put all the declarations at the root unless you have specific reasons not to.

Thanks for your reply. Although I tried your approach by adding all the namespace declarations in the root, still it gives me the following error when trying to perform the transformation. Namespace for prefix 'dc' has not been declared

@PawanSaha is it complaining about the stylesheet or about the input XML document? Do you maybe have <dc:something> elements in the input without an xmlns:dc declaration?

xml - How to add multiple namespace declaration in XSLT 2.0 - Stack Ov...

xml xslt xslt-2.0 transformation
Rectangle 27 4

It's a namespace problem. You'll have to add a namespace declaration for http://foo.bar/responsecode.xsd, and refer to elements using that namespace. More info can be found here.

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:test="http://foo.bar/responsecode.xsd">
  <xsl:template match="/">
    <html>
      <body>
        <h2>Responses</h2>

        <xsl:for-each select="test:root/test:responses/test:response">
          <xsl:choose>
            <xsl:when test="test:description != ''">
              <br/>'''&lt;description&gt;
              <br/>'''<xsl:value-of select="test:description" />
              <br/>'''&lt;/description&gt;
            </xsl:when>
          </xsl:choose>
          <br/>
          <xsl:value-of select="@code" />

        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

Note the "xmlns:test" in the xsl:stylesheet's attributes. I gave this a test and it works.

How to display XSD validated XML using XSLT - Stack Overflow

xml xslt xpath xsd namespaces
Rectangle 27 2

Remember that with XSLT, you don't create namespace declarations. Rather, you create elements with the right expanded name (namespace URI plus local name), and the serializer looks after getting the namespace declarations right. So you want the changeSet element to be in namespace http://www.liquibase.org/xml/ns/dbchangelog, you have to create it in that namespace, you can't just put a default namespace declaration on its parent element. If you create the changeSet element in a different namespace from its parent, the serializer will add a namespace declaration to reflect your (apparent) intent.

xslt - XSL add namespace definition to XML root only - Stack Overflow

xml xslt xslt-1.0
Rectangle 27 1

To make your xslt work with an xml file with name spaces you have to add the name space declaration to the style sheet. Also the default name space (name space without an pefix in xml) needs to have an prefix in xslt. To make your style sheet work try this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:v1="http://zanox.com/productdata/exportservice/v1">
    <xsl:output method="text" omit-xml-declaration="yes"/>

    <xsl:template match="/">
        <xsl:apply-templates select="//v1:product"/>
    </xsl:template>

    <xsl:template match="v1:product">
        <xsl:text>insert into data (name, program) values(</xsl:text>
        <xsl:value-of select="./v1:name"/>
        <xsl:text>,'</xsl:text>
        <xsl:value-of select="./v1:program"/>
        <xsl:text>'); </xsl:text>
    </xsl:template>

</xsl:stylesheet>

The xml declaration is the first line in most xml files:

<?xml version="1.0"?>
omit-xml-declaration="yes"
xsl:output method="xml"

The above xslt will generate the following output:

insert into data (name, program) values(BERTRAND BELIN+YANN DESTAL+D.RIVET,'3467');

xslt - Remove xmlns namespace form an xml with xsl - Stack Overflow

xml xslt namespaces xml-namespaces
Rectangle 27 1

To me, this looks like an encoding problem. Try to ensure that the files are encoded correctly in all cases.

For example, add encoding="UTF-8" to your XML and XSLT file. But note that this is only a declaration - it does not change the characters themselves.

Also, you could copy your XML content into a simple editor and save it explicitly as UTF-8. For instance, if you are using windows, copy the content into notepad, hit "Save as...". In the file dialog, you can choose "UTF-8" from a drop-down.

How to convert XML to HTML using XSLT in Java - Stack Overflow

java xml xslt xslt-1.0
Rectangle 27 0

If you're creating the mgh:message as a literal result element then provided those namespace declarations are in scope at the appropriate place it should just work:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:prism="http://prismstandard.org/namespaces/basic/2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1"
    xmlns:prl="http://prismstandard.org/namespaces/prl/2.0"
    xmlns:mgh="http://comp.com/prismPlus-XSD">

  <xsl:template match="/">
    <mgh:message xsi:schemaLocation="http://comp.com/prismPlus-XSD HeardsContent.xsd">
      <!-- etc -->

since literal result elements preserve the namespaces that are in scope at that point in the stylesheet.

You could of course just put the declarations on the mgh:message element itself rather than on the xsl:stylesheet, but then if you're creating the dc:* elements in another template you'd have to repeat the xmlns:dc there as well. Overall, I find it easier to put all the declarations at the root unless you have specific reasons not to.

Thanks for your reply. Although I tried your approach by adding all the namespace declarations in the root, still it gives me the following error when trying to perform the transformation. Namespace for prefix 'dc' has not been declared

@PawanSaha is it complaining about the stylesheet or about the input XML document? Do you maybe have <dc:something> elements in the input without an xmlns:dc declaration?

xml - How to add multiple namespace declaration in XSLT 2.0 - Stack Ov...

xml xslt xslt-2.0 transformation
Rectangle 27 0

If you are trying to use xslt you can add the namespace in to the stylesheet declaration. If you do that, you must make sure that there is a prefix or it will not work. If the source XML does not have a prefix, that is still fine, you add your own prefix in the stylesheet.

<xsl:stylesheet
    xmlns:fb="uri"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:template match="fb:foo/bar">
        <!--  do stuff here -->
    </xsl:template>
</xsl:stylsheet>

c# - XPATHS and Default Namespaces - Stack Overflow

c# xml xpath namespaces
Rectangle 27 0

If you're adding an xsl:import or xsl:include to the XSL-FO document, then that's wrong - these declarations should only appear in an XSLT stylesheet file.

No, there isn't enough information about what you are doing to know what you are doing wrong.

xslt - XSLFO - using xsl:import or xsl:include causes error when creat...

xslt pdf-generation xslt-1.0 xsl-fo
Rectangle 27 0

When you add the schema declaration, you are adding a default namespace to your XML document (xmlns="highway") which wasn't there before. This will then affect the interpretation of element references and XPATHs in the XSLT, because all your elements are now no longer <someElement>, they are <highway:someElement>. Check out this link for more information.

c# XSLT transform doesnt work if the XML file has a schema attached? -...

c# xslt xsd
Rectangle 27 0

I am using an application called Cast Iron to do these transformations. I have figured out the answer now, Cast Iron was adding these by default because it couldnt find them in the output given. Simply adding <parentElement></parentElement> fixed it because that is what it was expecting

Output from XSLT using copy-of adds an extra XML declaration? - Stack ...

xml xslt declaration
Rectangle 27 0

I would suggest to fix the code that does string processing instead of XML processing, as I don't think you will be able to add the namespace declaration with XSLT.

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

but in-scope namespace nodes are copied anyway with xsl:copy and when serializing the result tree the serializer of the XSLT processor will not create namespace declarations if they have already been output on a parent or ancestor element.

Ok so your final answer is: Not possible with XSLT. The copy-of does not do anything in my example above...

I mentioned the copy-of of namespaces as it is the only way in XSLT 1.0 to create such namespace nodes. But you are right, I don't see a way with XSLT to force the serializer of the XSLT processor to output namespace declaration attributes for namespace nodes which are already defined on a parent or ancestor. So enforcing the output you want with a namespace declaration on the root and the child elements is not possible with XSLT. You would need to use a DOM API or similar allowing you to create a namespace declaration attribute.

xslt - Add additional xmlns:xsi attributes to XML element - Stack Over...

xml xslt namespaces
Rectangle 27 0

If you are looking to remove namespace declarations from the category and authlist elements, try adding this additional template to your XSLT

<xsl:template match="*[namespace-uri()='']">
    <xsl:element name="{local-name()}">
        <xsl:apply-templates select="node()|@*" />
    </xsl:element>
</xsl:template>

This works because xsl:copy will copy across any namespace declarations from your input XML (whether they are used or not), so instead rather than copying the elements you create new elements, which won't have the declarations.

As from changing Name into Number, your XSLT looks like it is doing this correctly already. However, I would suggest that instead of using xsl:choose, you consider writing a series of templates, like so:

<xsl:template match="sAuthority/Name">
  <number>
    <xsl:apply-templates />
  </number>
</xsl:template>

<xsl:template match="Name/text()[.='P']">
  <xsl:value-of select="$P_1"/>
</xsl:template>

<xsl:template match="Name/text()[.='C']">
  <xsl:value-of select="$C_2"/>
</xsl:template>

<xsl:template match="Name/text()[.='S']">
  <xsl:value-of select="$S_3"/>
</xsl:template>

<xsl:template match="Name/text()[.='F']">
  <xsl:value-of select="$F_4"/>
</xsl:template>

Thanks a lot, Let me give this a try and see how it goes. Aprreciate it.

Ok your code for namespace worked, The namespaces on child elements were removed as expected great.... one question regarding your suggestion for Name to Number conversion...any advantages or disadvatages using template versus xsl:choose. just to remind that along with changing the value i also need to change the name of the element i.e from Name to Number? Thanks very much.

XSLT transformation from XML to XML - Stack Overflow

xslt
Rectangle 27 0

There's really no special secret to projecting namespaces and aliases into output documents - as with other xml documents, declare them in the root element, and then use the aliases. AFAIK the schemaLocation will need to be manually mapped onto the root element as an attribute. Here's a basic skeleton template (note that I've skipped most of the elements)

<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns:prism="http://prismstandard.org/namespaces/basic/2.0" 
                xmlns:dc="http://purl.org/dc/elements/1.1" 
                xmlns:prl="http://prismstandard.org/namespaces/prl/2.0" 
                xmlns:mgh="http://comp.com/prismPlus-XSD">

    <xsl:template match="/Heard">
    <mgh:message> <!--OR of course <msh xmlns="...">-->
       <xsl:attribute name="schemaLocation" 
                      namespace="http://www.w3.org/2001/XMLSchema-instance"
                      >http://comp.com/prismPlus-XSD HeardsContent.xsd</xsl:attribute>
      <mgh:article>
        <mgh:head>
          <dc:identifier>
            <xsl:value-of select="some/path/to/value"></xsl:value-of>
          </dc:identifier>
          <prism:keyword>
            <xsl:value-of select="Topic"></xsl:value-of>
          </prism:keyword>
        </mgh:head>
        <mgh:contentFeatureBody>
          <body> <!--Note, global namespace so no alias or xmlns-->
            <xsl:value-of select="TextBody"></xsl:value-of>
          </body>
        </mgh:contentFeatureBody>
      </mgh:article>
    </mgh:message>
  </xsl:template>
</xsl:stylesheet>

This produces the following output xml:

<?xml version="1.0" encoding="utf-8"?>
<mgh:message xsi:schemaLocation="http://comp.com/prismPlus-XSD HeardsContent.xsd" 
             xmlns:mgh="http://comp.com/prismPlus-XSD" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xmlns:prism="http://prismstandard.org/namespaces/basic/2.0" 
             xmlns:dc="http://purl.org/dc/elements/1.1" 
             xmlns:prl="http://prismstandard.org/namespaces/prl/2.0">
  <mgh:article>
    <mgh:head>
      <dc:identifier></dc:identifier>
      <prism:keyword>XX,YY,ZZ</prism:keyword>
    </mgh:head>
    <mgh:contentFeatureBody>
      <body>xxxxxxxxx</body>
    </mgh:contentFeatureBody>
  </mgh:article>
</mgh:message>

xml - How to add multiple namespace declaration in XSLT 2.0 - Stack Ov...

xml xslt xslt-2.0 transformation
Rectangle 27 0

I can tell you that you will get rid of all the xmlns="" by putting the xmlns="http://www.openarchives.org/OAI/2.0/" on the root of the stylesheet. As for the xmlns:xsi namespace declaration, I don't think you can enforce it with XSLT, it is in scope based on declaration on the ancestor, therefore the serializer does not need to add it to the descendant element.

xml - XSLT: How to force namespace in output child nodes - Stack Overf...

xml xslt xslt-2.0
Rectangle 27 0

Remember that with XSLT, you don't create namespace declarations. Rather, you create elements with the right expanded name (namespace URI plus local name), and the serializer looks after getting the namespace declarations right. So you want the changeSet element to be in namespace http://www.liquibase.org/xml/ns/dbchangelog, you have to create it in that namespace, you can't just put a default namespace declaration on its parent element. If you create the changeSet element in a different namespace from its parent, the serializer will add a namespace declaration to reflect your (apparent) intent.

xslt - XSL add namespace definition to XML root only - Stack Overflow

xml xslt xslt-1.0
Rectangle 27 0

There's really no special secret to projecting namespaces and aliases into output documents - as with other xml documents, declare them in the root element, and then use the aliases. AFAIK the schemaLocation will need to be manually mapped onto the root element as an attribute. Here's a basic skeleton template (note that I've skipped most of the elements)

<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns:prism="http://prismstandard.org/namespaces/basic/2.0" 
                xmlns:dc="http://purl.org/dc/elements/1.1" 
                xmlns:prl="http://prismstandard.org/namespaces/prl/2.0" 
                xmlns:mgh="http://comp.com/prismPlus-XSD">

    <xsl:template match="/Heard">
    <mgh:message> <!--OR of course <msh xmlns="...">-->
       <xsl:attribute name="schemaLocation" 
                      namespace="http://www.w3.org/2001/XMLSchema-instance"
                      >http://comp.com/prismPlus-XSD HeardsContent.xsd</xsl:attribute>
      <mgh:article>
        <mgh:head>
          <dc:identifier>
            <xsl:value-of select="some/path/to/value"></xsl:value-of>
          </dc:identifier>
          <prism:keyword>
            <xsl:value-of select="Topic"></xsl:value-of>
          </prism:keyword>
        </mgh:head>
        <mgh:contentFeatureBody>
          <body> <!--Note, global namespace so no alias or xmlns-->
            <xsl:value-of select="TextBody"></xsl:value-of>
          </body>
        </mgh:contentFeatureBody>
      </mgh:article>
    </mgh:message>
  </xsl:template>
</xsl:stylesheet>

This produces the following output xml:

<?xml version="1.0" encoding="utf-8"?>
<mgh:message xsi:schemaLocation="http://comp.com/prismPlus-XSD HeardsContent.xsd" 
             xmlns:mgh="http://comp.com/prismPlus-XSD" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xmlns:prism="http://prismstandard.org/namespaces/basic/2.0" 
             xmlns:dc="http://purl.org/dc/elements/1.1" 
             xmlns:prl="http://prismstandard.org/namespaces/prl/2.0">
  <mgh:article>
    <mgh:head>
      <dc:identifier></dc:identifier>
      <prism:keyword>XX,YY,ZZ</prism:keyword>
    </mgh:head>
    <mgh:contentFeatureBody>
      <body>xxxxxxxxx</body>
    </mgh:contentFeatureBody>
  </mgh:article>
</mgh:message>

xml - How to add multiple namespace declaration in XSLT 2.0 - Stack Ov...

xml xslt xslt-2.0 transformation
Rectangle 27 0

If your XSLT code can't handle this input XML, then either the input isn't actually XML, or you're presenting it incorrectly to the XSLT processor. The most likely explanation is that the encoding of the file is not what the XML declaration at the start of the file says it is; or perhaps there isn't an XML declaration, so the processor is assuming UTF-8, but it's actually iso-8859-1. The solution may be as simple as adding an XML declaration to the start of the file to declare the encoding as iso-8859-1.

I had this exact problem just recently; setting the encoding correctly worked.

xslt - replace special characters xml file - Stack Overflow

xml xslt
Rectangle 27 0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:strip-space elements="*" />

<xsl:key name="kCommon" match="*[starts-with(name(),'fils')]"
                        use="concat(name(),'|',.)" />

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

<xsl:template match="*[starts-with(name(),'fils')]
                      [count(key('kCommon',concat(name(),'|',.))) >= 2]">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
    <xsl:variable name="this-key" select="concat(name(),'|',.)" />
    <xsl:attribute name="id"><xsl:value-of select="
      count(preceding::*
             [starts-with(name(),'fils')]
             [count(.|key('kCommon',$this-key)) =
              count(  key('kCommon',$this-key))    ]
            ) + 1" /></xsl:attribute>
    <xsl:apply-templates select="node()"/>
  </xsl:copy>
</xsl:template>  

</xsl:stylesheet>
<Racine>
  <el1>
   <fils1>context1</fils1>
   <fils2>test1</fils2>
   <fils1>context1</fils1>
  </el1>
  <el2>
   <fils1>context2</fils1>
   <fils2>test2</fils2>
   <fils1>context2</fils1>
  </el2>
  <el3>
   <fils1>context1</fils1>
  </el3>
</Racine>
<Racine>
  <el1>
    <fils1 id="1">context1</fils1>
    <fils2>test1</fils2>
    <fils1 id="2">context1</fils1>
  </el1>
  <el2>
    <fils1 id="1">context2</fils1>
    <fils2>test2</fils2>
    <fils1 id="2">context2</fils1>
  </el2>
  <el3>
    <fils1 id="3">context1</fils1>
  </el3>
</Racine>

We build a key ('kCommon') of the fils elements that have both common name and common text content. We look for elements which have membership in thier key group of at least two - in other words filX type elements that have a name and text in common with at least one other filX element. This is our last template.

The set of all preceding fil elements in the common group. This set is given by...

preceding::*[starts-with(name(),'fils')]
key('kCommon',concat(name(),'|',.))

But because we will reference concat(name(),'|',.) quiet a few times, and in places where we don't have direct access to this context node, we just compute the concat() and substitute into Set 2 like this. Set 2 is now quick to compute.

key('kCommon',$this-key)

And then we take a set intersection using the Kaysian method.

$set1[count(.|$set2)=count($set2)]

This intersection is the set of all like-minded element to this one that preceded it. We just count them up and add one, and this gives us an ordinal for the id property.

<el2>        <fils1 id="1">context2</fils1>        <fils2>test2</fils2>        <fils1 id="2">context2</fils1>      </el2>      <el3>        <fils1 id="3">context1</fils1>      </el3>

how to check an existing node and its contains in an xml file using xs...

xslt xslt-1.0
Rectangle 27 0

It looks like what you are trying to do is add a variable declaration dynamically to your XSLT to create a new XSLT which is then saved and used in displaying the XML? Rather than work out why your code is not working, I would suggest you take a different approach to the problem.

Instead of trying to modify the XSLT by adding new statements and then opening the XML in the browser, you could add a parameter to your XSLT stylesheet, and use XSLCompiledTransform to perform the transformation in the program itself, passing in the parameter as it does so, and then open the resultant HTML in the browser.

To start with you would have have an xsl:param in your XSLT . (Directly under the xsl:stylesheet)

<xsl:param name="theStreet" />

Then, you would use the XSLCompiledTransform class to actually perform the transformation to HTML. Here is a sample of the code (using a hard-coded street name in this case).

using System.Diagnostics;
using System.Xml;
using System.Xml.Xsl;

namespace ConsoleApplication1
{
  class Program
  {
    private const string XML_FILE = @"Documents\ltcstops.xml";
    private const string XSLT_FILE_IN = @"Documents\ltcstops.xslt";
    private const string HTML_FILE_OUT = @"Documents\ltcstops.html";

    static void Main(string[] args)
    {
      // Create the XslCompiledTransform and load the stylesheet.
      XslCompiledTransform xslt = new XslCompiledTransform();
      xslt.Load(XSLT_FILE_IN);

      // Create the XsltArgumentList.
      XsltArgumentList xslArg = new XsltArgumentList();

      // Create a parameter which represents the current date and time.
      string streetName = "Adelaide & Ada NB";
      xslArg.AddParam("theStreet", "", streetName);

      // Transform the file. 
      using (XmlWriter w = XmlWriter.Create(HTML_FILE_OUT))
      {
        xslt.Transform(XML_FILE, xslArg, w);
      }

      Process proc = new System.Diagnostics.Process();
      proc.StartInfo.FileName = "iexplore";
      proc.StartInfo.Arguments = HTML_FILE_OUT;
      proc.Start();
    }
  }
}

The HTML that is opened up should then just show the details of the selected street name.

c# - No nodes found with XPathNavigator.Select(xpath) - Stack Overflow

c# xml xslt xpath
Rectangle 27 0

You can't produce the output you're looking for using XSLT because it is not namespace-well-formed, and XSLT always operates on namespace-well-formed XML. If you want to use a prefixed element name then the serializer must add the appropriate namespace declaration in order to produce legal output.

Even if there were a way to produce that output I'd still strongly advise against it because any other XML tool that tries to consume the data will complain about the undeclared namespace.

Im sorry but you have the reason

xml - XSLT Addenda Namespaces CFDI - Stack Overflow

xml xslt namespaces