2016-07-02 11 views
0

、以下を達成したい、所望の出力(テキスト)要約中のSOXSLTは:テキストへの変換XMLは、私は、XSLTに新しいです

01|1596056|12434F 
02|1233| |567| 

を必要とするXML入力以下

<?xml version="1.0" encoding="utf-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ser="http://xyz.com.zr/l8q/12Q/service/"> 
    <soapenv:Header> 
     <ser:User> 
      <!-- comment --> 
      <Username/> 
      <password/> 
     </ser:User> 
    </soapenv:Header> 
    <soapenv:Body> 
     <mainTag> 
      <abc>1596056</abc> 
      <asdd>12434F</asdd> 
      <childtag> 
       <asdf>1233</asdf> 
       <qwe>567</qwe> 
      </childtag> 
     </mainTag> 
    </soapenv:Body> 
</soapenv:Envelope> 

されています以下知ることでinterstedて所望の出力は、ロジックは

である以下

1) how can i make the text output from xslt. 
2) how to make/avoid newline (i.e break). 
3) how to generate spaces in text. 

詳細を

01  = this is line number in the text (first line) 
1596056 = <abc> 
12434F = <asdd> 

02  = this is line number in the text (second line) 
1233 = <asdf> 
567  = <qwe> 

おかげ

+0

「 – Pawel

+0

の例はあいまいです。ここで適用する必要があるロジックを説明してください。 –

+0

私はあなたの例が何を定数であるか、単なる例であるかはまだ分かりません。 –

答えて

0

あなたのロジックは、やや矛盾しているが、私はそれにこだわるつもりはありません。代わりに、私は出力を生成し、目標1)2)と3)に答えるxslを書いた。私はrelavantコードポイントにコメントを埋め込んだ。

これはxsltの基本的な概念ですので、私がxsltを使って作業することについてのバックグラウンドの読書をすることをお勧めします。これにはたくさんのリソースがあります。http://www.w3schools.comが気になるのですが、もちろんウェブにはもっと多くのものがあります。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 

<!-- 1) output method is "text" --> 
<xsl:output method="text" version="1.0" encoding="UTF-8"/> 

<!-- identity transform, apply templates without output --> 
<xsl:template match="@*|node()"> 
    <xsl:apply-templates select="@*|node()"/> 
</xsl:template> 

<!-- matches on soap envolpe body Body for the namespace http://schemas.xmlsoap.org/soap/envelope/ --> 
<xsl:template match="s:Body"> 
    <!-- list of tags that you want to count --> 
    <xsl:apply-templates select="mainTag | mainTag/childtag "/> 
</xsl:template> 

<xsl:template match="mainTag"> 
    <!-- output context position from within nodeset specified with the apply-templates above--> 
    <xsl:value-of select="concat('0',position())"/> 
    <xsl:text>|</xsl:text> 
    <xsl:value-of select="abc"/> 
    <xsl:text>|</xsl:text> 
    <xsl:value-of select="asdd"/> 
    <!-- 2) new line using entity --> 
    <xsl:text>&#13;</xsl:text> 
</xsl:template> 

<xsl:template match="childtag"> 
    <xsl:value-of select="concat('0',position())"/> 
    <xsl:text>|</xsl:text> 
    <xsl:value-of select="asdf"/> 
    <!-- 3) you can include a space within the xsl:text --> 
    <xsl:text>| |</xsl:text> 
    <xsl:value-of select="qwe"/> 
    <xsl:text>|</xsl:text> 
    <!-- 2) new line using entity --> 
    <xsl:text>&#13;</xsl:text> 
</xsl:template> 

</xsl:stylesheet> 
関連する問題