Re: [xsl] Namespaces and XSD

Subject: Re: [xsl] Namespaces and XSD
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 18 Dec 2014 20:59:20 -0000
Put the namespace declaration on the `xsl:stylesheet` element, that way
it applies to all result elements in your code.
--
Diese Nachricht wurde von meinem Android Mobiltelefon mit GMX Mail
gesendet.

"Craig Sampson craig.sampson@xxxxxxx"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>schrieb:

  Hi,

  I&rsquo;ve been using DTDs with my XML for years. Now I am trying to
  replace one of my DTDs with an XSD. I&rsquo;ve been told that the
  root element of the XML I am outputting from an XSLT transform should
  have a namespace that corresponds to the targetNamespace of my
  schema.

  So far so good. I output the root element with the namespace. But now
  some of the child elements are being output with
  xslns=&rdquo;&rdquo;. I&rsquo;ve tried everything I can think of to
  eliminate this extra namespaces from being output. (I am running
  SAXON EE and using XSLT 2.0)

  I&rsquo;ve tried adding xpath-default-namespace= to the value of the
  targetNamespace. I&rsquo;ve tried it with &ldquo;&rdquo;. Neither
  work.

    I&rsquo;ve tried replacing generized template matches, using copy,
  with specific templates that specify which attributes to output.

    I finally removed the namespace from the root element so it&rsquo;s
  not output anymore. Now I have no extraneous namespaces in my output.
  But, how will the output XML file know which schema defines it?

  How can I get rid of the unwanted namespace?

  Is there another way to reference the schema (XSD) from the XML
  document without adding a namespace to the root element?

  Thanks,

  Craig

  Here&rsquo;s a snippet of the XML source file I am transforming:

  <?xml version="1.0" encoding="UTF-8"?>

  <!--Arbortext, Inc., 1988-2012, v.4002-->

  <!DOCTYPE refDictEntry PUBLIC "-//SAS//DTD authoring 13.0//EN"
  "authoring.dtd">

  <refDictEntry docAlias="lefunctionsref"

  eid="p0xkrj83an7dknn1sgukpmnphcje" type="function" xml:lang="en">

  <commandLineHelpEntry
  eid="p05b61n8f36dwgn1gs1h1l6biwuj">ABS</commandLineHelpEntry>

  <indexEntry includeInSyntaxIndex="yes"><?Pub Dtl?><primary><?Pub
  Dtl?>ABS

  function</primary></indexEntry><indexEntry><?Pub Dtl?><primary><?Pub
  Dtl?>absolute

  value</primary></indexEntry>

  <title>ABS Function</title>

  <shortDescription>Returns the absolute value.</shortDescription>

  <summary>

  <category>Mathematical</category>

  </summary>

  <syntax eid="p07w43trquf74on1ct3ur17des7e">

  <syntaxSimple eid="p005cpxu5su0dkn1b6to129kl254">

  <syntaxLevel><keyword>ABS</keyword>(<userSuppliedSyntaxValue

  link="p1shy0v9fx5303n11p04kh3zsvm3">argument</userSuppliedSyntaxValue>)</syntaxLevel>

  </syntaxSimple>

  Here&rsquo;s the title template so you can see I am doing nothing to
  output a namespace:

  <xsl:template match="title[parent::refDictEntry]">

  <title>

  <xsl:choose>

  <xsl:when test="string-length(substring-before(normalize-space(.),'
  '))=0">

  <xsl:apply-templates/> <!-- no word space found so assume only one
  word in title -->

  </xsl:when>

  <xsl:otherwise>

  <xsl:value-of select="substring-before(normalize-space(.),' ')"/>
  <!-- get first word in title -->

  </xsl:otherwise>

  </xsl:choose>

  </title>

  </xsl:template>

  Here&rsquo;s a snippet of output with no namespace on the
  refDictEntryCjollection root element:

  <?xml version="1.0" encoding="UTF-8"?>

  <refDictEntryCollection eid="n1ewuqnosopv1kn1vx2dx8l3rchi"
  xml:lang="en">

  <refDictEntry eid="p0xkrj83an7dknn1sgukpmnphcje"

  type="function"

  xml:lang="en"

  docAlias="lefunctionsref">

  <?myURI
  http://support.sas.com/documentation/cdl/en/lefunctionsref/1/HTML/default/viewer.htm#p0xkrj83an7dknn1sgukpmnphcje.htm?>

  <title>ABS</title>

  <shortDescription>Returns the absolute value.</shortDescription>

  <summary>

  <category>Mathematical</category>

  </summary>

  <syntax eid="p07w43trquf74on1ct3ur17des7e">

  <syntaxSimple eid="p005cpxu5su0dkn1b6to129kl254">

  <syntaxLevel>

  <keyword>

  Here&rsquo;s the same snippet when I put the namespace on the root
  element. Notice the title, shortDescription, summary and syntax
  elements now have null namespaces.

  <?xml version="1.0" encoding="UTF-8"?>

  <refDictEntryCollection
  xmlns="http://www.sas.com/xml/namespace/sas_doc_xis_refDictEntryCollection-1.0";

  eid="n1ewuqnosopv1kn1vx2dx8l3rchi"

  xml:lang="en">

  <refDictEntry eid="p0xkrj83an7dknn1sgukpmnphcje"

  type="function"

  xml:lang="en"

  docAlias="lefunctionsref">

  <?myURI
  http://support.sas.com/documentation/cdl/en/lefunctionsref/1/HTML/default/viewer.htm#p0xkrj83an7dknn1sgukpmnphcje.htm?>

  <title xmlns="">ABS</title>

  <shortDescription xmlns="">Returns the absolute
  value.</shortDescription>

  <summary xmlns="">

  <category>Mathematical</category>

  </summary>

  <syntax xmlns="" eid="p07w43trquf74on1ct3ur17des7e">

  <syntaxSimple eid="p005cpxu5su0dkn1b6to129kl254">

  <syntaxLevel>

  <keyword>

  And finally here&rsquo;s the title element defined in the schema:

  <xs:element name="title">

  <xs:complexType mixed="true">

  <xs:choice minOccurs="0" maxOccurs="unbounded">

  <xs:element ref="statValue"/>

  <xs:element ref="subscript"/>

  <xs:element ref="superscript"/>

  <xs:element ref="userSuppliedValue"/>

  <xs:element ref="windowName"/>

  </xs:choice>

  </xs:complexType>

  </xs:element>

  XSL-List info and archiveEasyUnsubscribe (by email)

XSL-List info and archiveEasyUnsubscribe (by email)

Current Thread