2

次の XML があります。

<section editable="true">
  <p>If you have any questions about the project at Test School or how we plan to use the results, please contact <contact>Al c</contact><contact_info> at <contact_email>email address</contact_email> or <contact_phone>phone number</contact_phone>.</contact_info></p>
  <p>Your feedback is valuable, and <strong>I</strong> want to thank you personally for considering this request.</p>
  <p>Sincerely,</p>
</section>

このフォームを作成するための新しい要件があります。

<textarea>If you have any questions about the project at Test School or how we plan to use the results, please contact</textarea>
<input type="text" value="Al c " />
<input type="text" value="at email address or phone number." />
<textarea>Your feedback is valuable, and I want to thank you personally for considering this request.
 Sincerely,</textarea>

テキスト入力は単純で、前のセクション用に 1 つの大きなテキストエリアを作成することができましたが、ここ数時間、preceding-sibling:: と following-sibling:: を取得しようとしてもうまくいきませんでした。私は単純なものが欠けていると確信しています。

4

1 に答える 1

2

この変換

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:key name="kFollowing" match="p[not(contact | contact_info)]"
  use="generate-id(preceding-sibling::*
                             [not(self::p)
                            or
                              not(contact | contact_info)
                              ]
                               [1]
                       )"/>

 <xsl:template match="/*">
  <xsl:apply-templates select="*[1]"/>
 </xsl:template>
 <xsl:template match="p/text()">
     <textarea><xsl:value-of select="."/></textarea>
 </xsl:template>

 <xsl:template match="p[contact | contact_info]">
   <xsl:apply-templates/>
   <xsl:apply-templates select="following-sibling::*[1]"/>
 </xsl:template>

 <xsl:template match="contact | contact_info">
  <input type="text" value="{normalize-space()}"/>
 </xsl:template>

 <xsl:template match="p[not(contact | contact_info)][1]">
  <textarea>
    <xsl:copy-of select=
    "(.|key('kFollowing', generate-id()))//text()"/>
  </textarea>
 </xsl:template>
</xsl:stylesheet>

提供されたXMLドキュメントに適用した場合

<section editable="true">
    <p>If you have any questions about the project at Test School or how we plan to use the results, please contact 
        <contact>Al c</contact>
        <contact_info> at 
            <contact_email>email address</contact_email> or 
            <contact_phone>phone number</contact_phone>.
        </contact_info>
    </p>
    <p>Your feedback is valuable, and 
        <strong>I</strong> want to thank you personally for considering this request.
    </p>
    <p>Sincerely,</p>
</section>

必要な正しい結果を生成します

<textarea>If you have any questions about the project at Test School or how we plan to use the results, please contact 
        </textarea>
<input type="text" value="Al c"/>
<input type="text" value="at email address or phone number."/>
<textarea>Your feedback is valuable, and 
        I want to thank you personally for considering this request.
    Sincerely,</textarea>
于 2012-04-06T13:01:15.090 に答える