Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5842243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:59:31+00:00 2026-05-22T11:59:31+00:00

I have the following node I need to parse using XSLT 1.0 from xml

  • 0

I have the following node I need to parse using XSLT 1.0 from xml file

<log>Passed -ID:1 -Log:
Passed -ID:2 -Log:Suite
File/Folder
Failed -ID:3 -Log:Suite
Validate Install Failed
Passed -ID:4 -Log:
</log>

Here is the -ID: -Log:

as you can see can be written on one line or on multiple lines.

In result I would like to get another xml file where the data from node will be parsed. If record with ID was Passed then I need to write “/>.
If record was Failed then I need to write

<testcase name="<ID Name>">
  <failure message="<Log Message>"/>
</testcase>

In other words I need to get this xml file.

<xml>
   <testcase name="1"/>
   <testcase name="2"/>
   <testcase name="3">
      <failure message="Suite Validate Install Failed"/>
   </testcase>
   <testcase name="4"/>
</xml>

What do you think can be best way to do this?

The xml file is actually very big and I provided here only one node I need to parse. I’m using xslt because I’m getting other information from other nodes which I also need for result xml files.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:59:32+00:00Added an answer on May 22, 2026 at 11:59 am

    The following XSLT demonstrates how to split log content in tokens just using tokenize(). There are probably better choices with XSLT 2.0 (for example xsl:analyze-string), but because of using tokenize() only, this solution is applicable also to XSLT 1.0 extended with EXSLT templates.


    XSLT 2.0 tested on Saxon-B 9.0.0.2J

    <xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
    
        <xsl:template match="/">
            <xml>
                <xsl:variable name="string" select="."/>
    
                <xsl:variable name="pass" select="tokenize($string,'Passed -ID:')[not(position()=1)]"/>
    
                <xsl:for-each select="$pass">
    
                    <xsl:choose>
                        <xsl:when test="contains(.,'Failed -ID:')">
                            <xsl:variable name="failure" select="tokenize(.,'Failed -ID:')"/>
    
                            <xsl:for-each select="$failure">
                                <xsl:choose>
                                    <xsl:when   test="position()=1">
                                        <testcase name="{tokenize(.,'\s-Log:')[1]}"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:variable name="tc" select="tokenize(.,'\s-Log:')"/>
                                        <testcase name="{$tc[1]}">
                                            <failure message="{$tc[2]}"/>
                                        </testcase>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:for-each>
                        </xsl:when>
    
                        <xsl:otherwise>
                            <testcase name="{tokenize(.,'\s-Log:')[1]}"/>
                        </xsl:otherwise>
    
                    </xsl:choose>
                </xsl:for-each>
                <xsl:apply-templates/>
            </xml>
        </xsl:template>
    
        <xsl:template match="log"/>
    
    
    </xsl:stylesheet>
    

    The above XSLT applied on the following input:

    <log>Passed -ID:1 -Log:
    Passed -ID:2 -Log:Suite
    File/Folder
    Failed -ID:3 -Log:Suite
    Validate Install Failed
    Passed -ID:4 -Log:
    Failed -ID:5 -Log:aaaaaa
    Failed -ID:6 -Log:dfsfsdf
    Failed -ID:7 -Log:dsfsfs
    fsdfsdfsdfsdfs
    Passed -ID:8 -Log:dfsdfsf
    Failed -ID:9 -Log:dfsdfs
    </log>
    

    Produces the following output:

    <xml>
       <testcase name="1"/>
       <testcase name="2"/>
       <testcase name="3">
          <failure message="Suite&#xA;Validate Install Failed&#xA;"/>
       </testcase>
       <testcase name="4"/>
       <testcase name="5">
          <failure message="aaaaaa&#xA;"/>
       </testcase>
       <testcase name="6">
          <failure message="dfsfsdf&#xA;"/>
       </testcase>
       <testcase name="7">
          <failure message="dsfsfs&#xA;fsdfsdfsdfsdfs&#xA;"/>
       </testcase>
       <testcase name="8"/>
       <testcase name="9">
          <failure message="dfsdfs&#xA;"/>
       </testcase>
    </xml>
    

    Note that &#xA; is due to line-feeds of the source text appearing because we are placing the content inside the attribute value. To get rid of that it would be better to include the message as content of the element failure. Anyway the following article deals with tricky spaces.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have following attribute value in my XML node: CommandLine=copy $(TargetPath) ..\..\&#x0D;&#x0A;echo
I have an xml file that I am parsing and I have the following
I have the following XML LINQ query from my XDocument. var totals = (from
I have the following XML structure: <node name=A> <node name=B> <node name=C/> <node name=D/>
I have a project with a manifest file with the following node: <requestedExecutionLevel level=requireAdministrator
I have the following HTML node structure: <div id=foo> <div id=bar></div> <div id=baz> <div
I have the following input: <node TEXT=txt> <node TEXT=txt> <node TEXT=txt/> <node TEXT=txt/> </node>
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following text in a file 23456789 When I tried to replace the
I have the following xml: <listaGiros> <giro> <idGiro type=int>89</idGiro> <nombreGiro type=varchar>foo</nombreGiro> </giro> <giro> <idGiro

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.