Partage
  • Partager sur Facebook
  • Partager sur Twitter

Name an element with the name of its XSLT attribut

    28 juin 2019 à 9:24:54

    Hello,
    I'm looking for XLST to edit an xml file. As explained in the title, I would like to rename my items with the name of their "name" attribute.
    My xml file :
    <doe name="titi">
        <bob name="toto">blabla</bob>
        <bob name="tutu">blabla </bob>
    </doe>
    The output xml file that I would like:
    <titi>
        <toto>blabla</toto>
        <tutu>blabla </tutu>
    </titi>
    I tried several things but I was sent back an "attribute" name "hab a bad value"
    <xsl:element name="@bob">
        <xsl:value-of select="$bob" />
    </xsl:element>
    or
    <xsl:element name="/doe/@bob">
        <xsl:value-of select="$bob" />
    </xsl:element>

    -
    Edité par Epyon9 28 juin 2019 à 9:26:41

    • Partager sur Facebook
    • Partager sur Twitter
      12 août 2019 à 4:16:49

      have you found a way to fix this problem? Can I know its solution?

      hole io

      • Partager sur Facebook
      • Partager sur Twitter
        12 août 2019 à 15:38:48

        Yes I found the solution:
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        	<xsl:output method="xml" indent="yes"/>
        	
        	<xsl:template match="/doe">
        		<xsl:element name="{@name}">
        			<xsl:for-each select= "child::bob">
        	                        <xsl:element name="{@name}">
        			                <xsl:value-of select= "node()"/>
        		    	        </xsl:element>
        	    	        </xsl:for-each>
        	        </xsl:element>
        	</xsl:template>
        
        </xsl:stylesheet>
        If you have other questions about the XSLT do not hesitate I improved a lot since my last post :)

        -
        Edité par Epyon9 12 août 2019 à 15:40:56

        • Partager sur Facebook
        • Partager sur Twitter
          5 juin 2020 à 11:59:26 - Message modéré pour le motif suivant : Toute forme de publicité est interdite


          Name an element with the name of its XSLT attribut

          × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
          × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
          • Editeur
          • Markdown