2010-09-01 5 views
0

Je veux faire une transformation XSLT 1.0 d'un xml où j'utilise le nœud. Maintenant, quand j'applique cela, il définit un espace de noms xmlns sur les éléments copiés, est-il possible d'éviter cela?copy-of sans espace de noms dans xlst1.0

C'est le xml d'entrée:

<ns0:Task xmlns:ns0="http://Sharepoint.Task"> 
    <UserName>FalcoLannoo</UserName> 
    <Title>Task1</Title> 
    <Description>Description_0</Description> 
    <Library>Library_0</Library> 
    <DueDate>1999-05-31</DueDate> 
    <Priority>10</Priority> 
</ns0:Task> 

Et j'utiliser cette xsl pour le transformer:

<?xml version="1.0" encoding="UTF-16"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 ns0" version="1.0" xmlns:tns="http://schemas.microsoft.com/sharepoint/soap/" xmlns:ns1="http://microsoft.com/wsdl/types/" xmlns:s0="http://Sharepoint.Batch" xmlns:ns0="http://Sharepoint.Batch"> 
    <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" /> 
    <xsl:template match="/"> 
    <xsl:apply-templates select="/s0:updates" /> 
    </xsl:template> 
    <xsl:template match="/s0:updates"> 
    <tns:UpdateListItems> 
    <tns:listName> 
     <xsl:value-of select="listName/text()" /> 
    </tns:listName> 
    <tns:updates> 
     <xsl:copy-of select="/s0:updates/Batch" /> 
    </tns:updates> 
    </tns:UpdateListItems> 
</xsl:template> 
</xsl:stylesheet> 

Et le fichier de sortie est la suivante:

<tns:UpdateListItems xmlns:tns="http://schemas.microsoft.com/sharepoint/soap/"  
xmlns:ns1="http://microsoft.com/wsdl/types/"> 
<tns:listName>{58887260-E5EB-4AB5-B105-E5DD57C8C8E0}</tns:listName> 
<tns:updates> 
    <Batch OnError="Continue" ListVersion="1" ViewName="" 
    xmlns:ns0="http://Sharepoint.Batch"> 
     <Method ID="1" Cmd="New"> 
      <Field Name="UserName">FalcoLannoo</Field> 
      <Field Name="Title">Task1</Field> 
      <Field Name="Description">Description_0</Field> 
      <Field Name="Library">Library_0</Field> 
      <Field Name="DueDate">1999-05-31</Field> 
      <Field Name="Priority">10</Field> 
     </Method> 
    </Batch> 
</tns:updates> 
</tns:UpdateListItems> 

Et cela est la ligne dont je veux me débarrasser: xmlns: ns0 = "http: //Sharepoint.Batch" (dans le noeud Batch)

thx

+0

Pouvez-vous publier votre code XSLT et le code XML que vous êtes en train de transformer? – Mark

+0

ok, édité avec des échantillons de code. –

+0

Je ne vois pas comment le XML d'entrée correspond à la feuille de style ou à la sortie? L'entrée XML parle aux éléments appelés ns0: Task et la feuille de style et la sortie parlent à Batch and Updates dans un espace de noms différent? – Robin

Répondre

0

D'abord, votre échantillon d'entrée ne correspond pas à votre sortie.

En second lieu, de http://www.w3.org/TR/xslt#copy-of

Lorsque le résultat est un ensemble de nœuds, tous les noeuds dans l'ensemble sont copiés dans ordre du document dans l'arbre de résultat; La copie d'un nœud d'élément copie les nœuds d'attribut , les nœuds d'espace de noms et les enfants du nœud d'élément ainsi que en tant que nœud d'élément lui-même.

Donc, ce comportement est voulu. Et c'est parfaitement logique car dans la portée les espaces de noms font partie de la structure.

Afin de se déshabiller namespaces portée, vous devez utiliser ce type de feuille de style:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:tns="http://schemas.microsoft.com/sharepoint/soap/" 
xmlns:s0="http://Sharepoint.Batch" 
exclude-result-prefixes="s0"> 
    <xsl:output omit-xml-declaration="yes"/> 
    <xsl:template match="s0:updates"> 
     <tns:UpdateListItems> 
      <tns:listName> 
       <xsl:value-of select="listName" /> 
      </tns:listName> 
      <tns:updates> 
       <xsl:apply-templates select="Batch" /> 
      </tns:updates> 
     </tns:UpdateListItems> 
    </xsl:template> 
    <xsl:template match="*"> 
     <xsl:element name="{name()}"> 
      <xsl:copy-of select="@*" /> 
      <xsl:apply-templates select="node()" /> 
     </xsl:element> 
    </xsl:template> 
</xsl:stylesheet> 

Avec cette entrée:

<ns0:updates xmlns:ns0="http://Sharepoint.Batch"> 
    <listName>list</listName> 
    <Batch OnError="Continue" ListVersion="1" ViewName=""> 
     <Method ID="1" Cmd="New"> 
      <Field Name="UserName">FalcoLannoo</Field> 
      <Field Name="Title">Task1</Field> 
      <Field Name="Description">Description_0</Field> 
      <Field Name="Library">Library_0</Field> 
      <Field Name="DueDate">1999-05-31</Field> 
      <Field Name="Priority">10</Field> 
     </Method> 
    </Batch> 
</ns0:updates> 

Sortie:

<tns:UpdateListItems 
xmlns:tns="http://schemas.microsoft.com/sharepoint/soap/"> 
    <tns:listName>list</tns:listName> 
    <tns:updates> 
     <Batch OnError="Continue" ListVersion="1" ViewName=""> 
      <Method ID="1" Cmd="New"> 
       <Field Name="UserName">FalcoLannoo</Field> 
       <Field Name="Title">Task1</Field> 
       <Field Name="Description">Description_0</Field> 
       <Field Name="Library">Library_0</Field> 
       <Field Name="DueDate">1999-05-31</Field> 
       <Field Name="Priority">10</Field> 
      </Method> 
     </Batch> 
    </tns:updates> 
</tns:UpdateListItems> 

Modifier: Code plus compact.

+0

** Note à moi-même: ** Cela fonctionnera avec XML 1.0.- Avec XML 1.1 la liaison de préfixe d'espace de noms devrait être réinitialisée comme '' –