0

一部の XML タグ内に二重パイプで区切られたデータがあり、区切られたテキストを XML に置き換え/変換したいと考えています。
区切られたテキストでも、次のようにコロンを使用して見出しとデータを区切ります: ||tagname:data||
見出しやタグ名は何でも構いませんが、これは一例にすぎません。そのため、何が得られるかは事前にわかりません。コロンの前にリストされているものを取り、それを使用する必要があります。

 <doc>
      <arr name="content">
      <str>  stream_source_info docname   stream_content_type text/html   stream_size 412   Content-Encoding ISO-8859-1   stream_name docname   Content-Type text/html; charset=ISO-8859-1   resourceName docname       ||phone:3282||email:Lori.KS@.edu||officenumber:D-107A||vcard:https://c3qa/profiles/vcard/profile.do?key=5c28d263-d8aa-4a8a-ae90-4e8b13de7a0b||photo:https://c3qa/profiles/photo.do?key=5c28d263-d8aa-4a8a-ae90-4e8b13de7a0b&amp;lastMod=1348674215846||pronunciation:https://c3qa/profiles/audio.do?key=5c28d263-d8aa-4a8a-ae90-4e8b13de7a0b&amp;lastMod=1348674215846||  </str>
    </arr>
</doc>  

XSLT を使用して、この XML をこれに変換できますか?

 <doc>
      <arr name="content">
      <str>  stream_source_info docname   stream_content_type text/html   stream_size 412   Content-Encoding ISO-8859-1   stream_name docname   Content-Type text/html; charset=ISO-8859-1   resourceName docname  
          <phone>3282</phone>
          <email>Lori.KS@.edu</email>
          <officenumber>D-107A</officenumber>
          <vcard>https://c3qa/profiles/vcard/profile.do?key=5c28d263-d8aa-4a8a-ae90-4e8b13de7a0b</vcard>
          <photo>https://c3qa/profiles/photo.do?key=5c28d263-d8aa-4a8a-ae90-4e8b13de7a0b&amp;lastMod=1348674215846</photo>
          <pronunciation>https://c3qa/profiles/audio.do?key=5c28d263-d8aa-4a8a-ae90-4e8b13de7a0b&amp;lastMod=1348674215846</pronunciation>
      </str>
    </arr>
</doc>  

URL は CDATA でラップする必要があり、区切りバージョンを置き換える必要があります。
誰かが私を正しい方向に向けることができますか? ありがとうございました、

4

1 に答える 1

1

analyze-stringSaxon 9.5 スタイルシートを使用すると、役立ちます

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes"/>

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

<xsl:template match="str">
  <xsl:copy>
    <xsl:analyze-string select="." regex="\|((\|[^|]+\|)+)\|">
      <xsl:matching-substring>
        <xsl:analyze-string select="regex-group(1)" regex="\|(\w+):([^|]+)\|">
          <xsl:matching-substring>
            <xsl:element name="{regex-group(1)}">
              <xsl:value-of select="regex-group(2)"/>
            </xsl:element>
          </xsl:matching-substring>
        </xsl:analyze-string>
      </xsl:matching-substring>
      <xsl:non-matching-substring>
        <xsl:value-of select="."/>
      </xsl:non-matching-substring>
    </xsl:analyze-string>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

入力を変換します

<doc>
      <arr name="content">
      <str>  stream_source_info docname   stream_content_type text/html   stream_size 412   Content-Encoding ISO-8859-1   stream_name docname   Content-Type text/html; charset=ISO-8859-1   resourceName docname       ||phone:3282||email:Lori.KS@.edu||officenumber:D-107A||vcard:https://c3qa/profiles/vcard/profile.do?key=5c28d263-d8aa-4a8a-ae90-4e8b13de7a0b||photo:https://c3qa/profiles/photo.do?key=5c28d263-d8aa-4a8a-ae90-4e8b13de7a0b&amp;lastMod=1348674215846||pronunciation:https://c3qa/profiles/audio.do?key=5c28d263-d8aa-4a8a-ae90-4e8b13de7a0b&amp;lastMod=1348674215846||  </str>
    </arr>
</doc>

結果に

<doc>
      <arr name="content">
      <str>  stream_source_info docname   stream_content_type text/html   stream_size 412   Content-Encoding ISO-8859-1   stream_name docname   Content-Type text/html; charset=ISO-8859-1   resourceName docname       <phone>3282</phone>
         <email>Lori.KS@.edu</email>
         <officenumber>D-107A</officenumber>
         <vcard>https://c3qa/profiles/vcard/profile.do?key=5c28d263-d8aa-4a8a-ae90-4e8b13de7a0b</vcard>
         <photo>https://c3qa/profiles/photo.do?key=5c28d263-d8aa-4a8a-ae90-4e8b13de7a0b&amp;lastMod=1348674215846</photo>
         <pronunciation>https://c3qa/profiles/audio.do?key=5c28d263-d8aa-4a8a-ae90-4e8b13de7a0b&amp;lastMod=1348674215846</pronunciation>  
      </str>
    </arr>
</doc>
于 2013-05-25T09:19:12.853 に答える