Announcement

Collapse
No announcement yet.

last Element

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • last Element

    Hallo,

    habe den untere XML_Struktur gegeben. Ich möchte nun das mein Template mir die vorhandene Strukrur kopiert und nach dem Tag "gg" mir mir einen weiteren Tag <end>EndeStrukt</end> hinzufügt.
    Kann mir da jemand behilflich sein?

    myTemplate.xsl
    Code:
    <xsl:template match="tt">	
    <xsl:copy-of select="." />
    </xsl:template>
    XML...
    Code:
    <tt>
    <test>
    <titel>Telefon</titel>
    <telefon><name>Hans</name><nummer>069 - 11727349874</nummer></telefon>
    <telefon><name>Sabine</name><nummer>040 - 116343432094</nummer></telefon>
    <gg>Hallo</gg>
    </test>
    
    
    <bb>
    	<name> neu</name>
    	
    </bb>
    </tt>

  • #2
    Zwei Templates reichen:

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

    Comment


    • #3
      danke dir , funktioniert so weit.
      Allerdings kann er vor dem Tag "Test "nicht den neuen Tag hinzufügen, wenn die Eingangsdatei wie folgt beginnt.

      <tt xmlns="http://www.dd/personal">

      Comment


      • #4
        Originally posted by sirair View Post
        Allerdings kann er vor dem Tag "Test "nicht den neuen Tag hinzufügen, wenn die Eingangsdatei wie folgt beginnt.

        <tt xmlns="http://www.dd/personal">
        Mit XSLT 1.0 kannst du das in dem Fall folgendermaßen lösen:
        Code:
        <xsl:stylesheet
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
          version="1.0"
          xmlns:p="http://www.dd/personal"
          xmlns="http://www.dd/personal"
          exclude-result-prefixes="p">
        
        <xsl:template match="@* | node()">
          <xsl:copy>
           <xsl:apply-templates select="@* | node()"/>
          </xsl:copy>
        </xsl:template>
        
        <xsl:template match="p:tt/p:test">
          <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
            <end>EndeStrukt</end>
          </xsl:copy>
        </xsl:template>
        
        </xsl:stylesheet>
        Mit XSLT 2.0 reicht:
        Code:
        <xsl:stylesheet
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
          version="2.0"
          xpath-default-namespace="http://www.dd/personal"
          xmlns="http://www.dd/personal">
        
        <xsl:template match="@* | node()">
          <xsl:copy>
           <xsl:apply-templates select="@* | node()"/>
          </xsl:copy>
        </xsl:template>
        
        <xsl:template match="tt/test">
          <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
            <end>EndeStrukt</end>
          </xsl:copy>
        </xsl:template>
        
        </xsl:stylesheet>

        Comment

        Working...
        X