SORU
13 Aralık 2008, CUMARTESİ


XML XSLT Kullanarak CSV

Aşağıdaki XML belgesi var:

<projects>
  <project>
   <name>Shockwave</name> 
   <language>Ruby</language> 
   <owner>Brian May</owner> 
   <state>New</state> 
   <startDate>31/10/2008 0:00:00</startDate> 
  </project>
  <project>
   <name>Other</name> 
   <language>Erlang</language> 
   <owner>Takashi Miike</owner> 
   <state> Canceled </state> 
   <startDate>07/11/2008 0:00:00</startDate> 
  </project>
...

Ve dönüşümü (XSLT) sonucu güzel olsun istiyorum:

Shockwave,Ruby,Brian May,New,31/10/2008 0:00:00
Other,Erlang,Takashi Miike,Cancelled,07/11/2008 0:00:00

Herkes bunu başarmak için XSLT biliyor mu? Kullanıyorum .önemli olan bu durumda net.

Teşekkürler!

CEVAP
13 Aralık 2008, CUMARTESİ


İşte Program aracılığıyla ayarlama yapılandırılabilir parametreleri ile bir versiyonu:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" encoding="utf-8" />

  <xsl:param name="delim" select="','" />
  <xsl:param name="quote" select="'"'" />
  <xsl:param name="break" select="'
'" />

  <xsl:template match="/">
    <xsl:apply-templates select="projects/project" />
  </xsl:template>

  <xsl:template match="project">
    <xsl:apply-templates />
    <xsl:if test="following-sibling::*">
      <xsl:value-of select="$break" />
    </xsl:if>
  </xsl:template>

  <xsl:template match="*">
    <!-- remove normalize-space() if you want keep white-space at it is --> 
    <xsl:value-of select="concat($quote, normalize-space(), $quote)" />
    <xsl:if test="following-sibling::*">
      <xsl:value-of select="$delim" />
    </xsl:if>
  </xsl:template>

  <xsl:template match="text()" />
</xsl:stylesheet>

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • IGN

    IGN

    19 EYLÜL 2006
  • NewsyTech

    NewsyTech

    2 AĞUSTOS 2010
  • Sergio Fernandez

    Sergio Ferna

    1 EKİM 2009