0
<windows-command-output>
  <metadata>
    <status>success</status>
  </metadata>
  <targets-output>
    <target-output>
      <metadata>
        <os-id>Windows Server 2008</os-id>
        <os-version></os-version>
        <status>success</status>
      </metadata>
      <commands-output>
        <command-output>
          <metadata>
            <command>dir /s D:\$RECYCLE.BIN\</command>
            <line-count>13</line-count>
            <execution-milliseconds>50</execution-milliseconds>
            <exit-code>0</exit-code>
            <status>success</status>
          </metadata>
          <output>
            <line index="1"> Volume in drive D is DATA</line>
            <line index="2"> Volume Serial Number</line>
            <line index="3"> Directory of D:\$RECYCLE.BIN\S-1-5-21-590445608-1855731889-617630493-633025</line>
            <line index="4">06/22/2022  03:27 PM                70 $I8WMUV8.xlsx</line>
            <line index="5">06/22/2022  03:27 PM                70 $IEZJMA9.xlsx</line>
            <line index="6">06/22/2022  03:27 PM                70 $IH5VLVD.xlsx</line>
            <line index="7">10/11/2018  09:57 AM            12,223 $R8WMUV8.xlsx</line>
            <line index="8">10/11/2018  09:59 AM            12,220 $REZJMA9.xlsx</line>
            <line index="9">10/11/2018  10:00 AM            11,366 $RH5VLVD.xlsx</line>
            <line index="10">               6 File(s)         36,019 bytes</line>
            <line index="11">     Total Files Listed:</line>
            <line index="12">               6 File(s)         36,019 bytes</line>
            <line index="13">               0 Dir(s)  15,750,713,344 bytes free</line>
          </output>
        </command-output>
      </commands-output>
    </target-output>
  </targets-output>
</windows-command-output>

how do I fetch the value " 6 File(s) 36,019 bytes" from the XML provided it can be placed anywhere in the XML and not specifically in index=10.

5
  • Why do you need to "search" for a fixed value you know? Do you know the string functions of XPath 1 and later and the regular expression support of XPath 2 and later? Commented Jun 22, 2022 at 20:43
  • Maybe helpful stackoverflow.com/a/70582811/917548 Commented Jun 22, 2022 at 20:53
  • New to XML and XSLT, I am trying to get the file size from the XML, in the above example its "6 File(s) 36,019 bytes" placed at index = 10, but the location index = 10 is not static it can be placed anywhere in the XML. Commented Jun 22, 2022 at 21:02
  • So what identifies the value you want to retrieve? Commented Jun 22, 2022 at 21:03
  • since I want to retrieve folder size that is value from "<line index="10"> 6 File(s) 36,019 bytes</line>", I want to search the XML where it contains word "Files(s)" and then fetch the value "<line index="10"> 6 File(s) 36,019 bytes</line>" Commented Jun 22, 2022 at 21:07

1 Answer 1

0

I want to search the XML where it contains word "Files(s)" and then fetch the value

That could be done simply by:

<xsl:value-of select="//line[contains(., 'File(s)')][1]"/>

Note that your example has two such lines; this retrieves the value of the first one of them.

1
  • Thank you, I got that. Commented Jun 22, 2022 at 21:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.