Differentiate between similar records

青春壹個敷衍的年華 提交于 2020-05-17 08:08:45

问题


I have some input XML that is auto generated(so I am unable to rename the fields accordingly):

<?xml version="1.0" encoding="UTF-8"?>
<csv-xml>
   <record>
      <csv-field-1>1</csv-field-1>
      <csv-field-2>12345</csv-field-2>
      <csv-field-3>7654321</csv-field-3>
      <csv-field-4>1</csv-field-4>
      <csv-field-5>08/08/19</csv-field-5>
      <csv-field-6>08/08/19</csv-field-6>
   </record>
   <record>
      <csv-field-1>2</csv-field-1>
      <csv-field-2>12345</csv-field-2>
      <csv-field-3>12345678</csv-field-3>
      <csv-field-4>3</csv-field-4>
   </record>
   <record>
      <csv-field-1>2</csv-field-1>
      <csv-field-2>12345</csv-field-2>
      <csv-field-3>22345679</csv-field-3>
      <csv-field-4>7</csv-field-4>
   </record>
   <record>
      <csv-field-1>2</csv-field-1>
      <csv-field-2>12345</csv-field-2>
      <csv-field-3>32345680</csv-field-3>
      <csv-field-4>6</csv-field-4>
   </record>
   <record>
      <csv-field-1>2</csv-field-1>
      <csv-field-2>12345</csv-field-2>
      <csv-field-3>42345681</csv-field-3>
      <csv-field-4>2</csv-field-4>
   </record>
   <record>
      <csv-field-1>3</csv-field-1>
      <csv-field-2>12345</csv-field-2>
      <csv-field-3></csv-field-3>
   </record>
</csv-xml>

I am trying to figure out how to use an XSLT transformation to take out the data I need when records have the same path/name.

I have tried using:

<xsl:copy-of select="/csv-xml/record/csv-field-2/node()"/>

But the output is:

1234512345123451234512345

Code Used:

<?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.1"   
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"
            media-type="text/plain"/>

<xsl:template match="/">
    <xsl:copy-of select="/csv-xml/record/csv-field-2/node()"/>
</xsl:template>

</xsl:stylesheet>

My expected result would be from the first 'csv-field-2' something like:

<name>12345</name>

My final goal is to be able to extract all the data needed from these XML's that may have more or less records using the same script. But that's a future problem.

来源:https://stackoverflow.com/questions/57458634/differentiate-between-similar-records

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!