none
XSLT - How to select below one level ?

    Question

  • Hi

    Using a varierty of tools, LinqPad, C#, Powershell and last XSL, i have been unable to crack the syntax to get below one level, i.e. all the code examples have something like "books/makers"

    In my case i want to iterate through the TestRun/ResultSummary/RunInfos/RunInfo items

    Nor matter what i try, i can't select this level, e.g.

        <xsl:for-each select="TestRun/ResultSummary/RunInfos/RunInfo">
    	<xsl:value-of select="Text"/>
    	OutCome = <xsl:value-of select="@outcome" />
        </xsl:for-each>

    Once i can get past this, i can they try queries to restrict the range.

    >> I would really appreciate if someone knows the factor X needed to get to deeper levels in XML.

    Friday, September 27, 2013 5:51 AM

Answers

  • Hi,

    Sorry for being late.

    >>Before i mark this off as answred, can you explain why the foo: namespace is needed ?

    I add this namesapce to make srue the two files under the same namespace.This is my before test files(Sorry for this).

    And actually it is not necessary. You can change ij to be:

    XSL:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet  version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >
      <xsl:template match="/">
        <html>
          <body>
            <h2>GN4 User Information</h2>
            <table border="1">
              <tr bgcolor="#9acd32">
                <th>OutCome</th>
                <!--<th>User Complete Name</th>-->
              </tr>
              <xsl:for-each select="result/ResultSummary/RunInfos/Runinfo">
                <tr>
                  <td>
                    OutCome=<xsl:value-of select="@outcomde"/>
                  </td>
                </tr>
              </xsl:for-each>
            </table>
          </body>
        </html>
      </xsl:template>
    </xsl:stylesheet>

    XML:

    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="1.xsl"?>
    <result  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    >
      <TestSettings></TestSettings>
      <Times></Times>
      <ResultSummary>
        <Counters></Counters>
        <RunInfos>
          <Runinfo outcomde="Warming1"></Runinfo>
          <Runinfo outcomde="Warming2"></Runinfo>
          <Runinfo outcomde="Warming3"></Runinfo>
        </RunInfos>
      </ResultSummary>
    </result>

    Note: The two files need to under the same directory because I have write the 'href' to be:

    href="1.xsl"

    Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Greg B Roberts Tuesday, October 01, 2013 12:18 PM
    Tuesday, October 01, 2013 11:36 AM

All replies

  • Hello Greg B Roberts,

    Thanks for visiting this forum.

    If I understand correctly, you want fetch the outcome value as below:

    With your description, I made a sample and please see it below:

    XML File:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet  version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="http://www.teradp.com/schemas/GN4/1/Results.xsd"
      exclude-result-prefixes="foo"
    >
      <xsl:template match="/">
        <html>
          <body>
            <h2>GN4 User Information</h2>
            <table border="1">
              <tr bgcolor="#9acd32">
                <th>OutCome</th>
                <!--<th>User Complete Name</th>-->
              </tr>
              <xsl:for-each select="foo:result/foo:ResultSummary/foo:RunInfos/foo:Runinfo">
                <tr>
                  <td>
                    OutCome=<xsl:value-of select="@outcomde"/>
                  </td>
                </tr>
              </xsl:for-each>
            </table>
          </body>
        </html>
      </xsl:template>
    </xsl:stylesheet>

    XSL File:

    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="S12-1.xsl"?>
    <result  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.teradp.com/schemas/GN4/1/Results.xsd">
      <TestSettings></TestSettings>
      <Times></Times>
      <ResultSummary>
        <Counters></Counters>
        <RunInfos>
          <Runinfo outcomde="Warming1"></Runinfo>
          <Runinfo outcomde="Warming2"></Runinfo>
          <Runinfo outcomde="Warming3"></Runinfo>
        </RunInfos>
      </ResultSummary>
    </result>

    And there is a thread before I posted that may help you below.
    http://social.msdn.microsoft.com/Forums/en-US/05c99a96-9842-4374-9d60-9115f14aa1a0/unable-to-insert-in-a-tr-the-content-of-an-attribute-from-xml-using-xslt

    If we do not name the XSL file and XML file to be the same namespace, it will fail.

    And could you please share your xml file since mine is created just depending on the image and may not correct.

    Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Monday, September 30, 2013 8:59 AM
  • Thank you for the detailed reply!!

    Before i mark this off as answred, can you explain why the foo: namespace is needed ?

    The input XML is a Microsoft produced build trx file, as you can see by the picture above, it has no namespace.

    Surely XSLT supports no namespace ?

    regards

    Monday, September 30, 2013 1:21 PM
  • Hi,

    Sorry for being late.

    >>Before i mark this off as answred, can you explain why the foo: namespace is needed ?

    I add this namesapce to make srue the two files under the same namespace.This is my before test files(Sorry for this).

    And actually it is not necessary. You can change ij to be:

    XSL:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet  version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >
      <xsl:template match="/">
        <html>
          <body>
            <h2>GN4 User Information</h2>
            <table border="1">
              <tr bgcolor="#9acd32">
                <th>OutCome</th>
                <!--<th>User Complete Name</th>-->
              </tr>
              <xsl:for-each select="result/ResultSummary/RunInfos/Runinfo">
                <tr>
                  <td>
                    OutCome=<xsl:value-of select="@outcomde"/>
                  </td>
                </tr>
              </xsl:for-each>
            </table>
          </body>
        </html>
      </xsl:template>
    </xsl:stylesheet>

    XML:

    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="1.xsl"?>
    <result  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    >
      <TestSettings></TestSettings>
      <Times></Times>
      <ResultSummary>
        <Counters></Counters>
        <RunInfos>
          <Runinfo outcomde="Warming1"></Runinfo>
          <Runinfo outcomde="Warming2"></Runinfo>
          <Runinfo outcomde="Warming3"></Runinfo>
        </RunInfos>
      </ResultSummary>
    </result>

    Note: The two files need to under the same directory because I have write the 'href' to be:

    href="1.xsl"

    Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Greg B Roberts Tuesday, October 01, 2013 12:18 PM
    Tuesday, October 01, 2013 11:36 AM
  • Thanks, in closing, what means did you use to process the xsl ?

    msxsl.exe, C# code ?

    NB: After fixing the typo  in'

                  OutCome=<xsl:value-of select="@outcome"/>

    it did not work for me. I tried

    TestRun/ResultSummary/RunInfos/RunInfo"

    and

    ResultSummary/RunInfos/RunInfo

    Tuesday, October 01, 2013 12:25 PM
  • Actually I process it by hand and I recommend to process it by hand because this is more control.

    If you are inserted in it, you can have a look at the link:

    http://www.w3schools.com/xsl/xsl_languages.asp

    Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, October 01, 2013 12:36 PM
  • Thanks, still not working even with your samples, don't understand href="1.xsl" reference, what it means, what is expected.
    Wednesday, October 02, 2013 1:01 AM
  • Hi,

    The XLS file is stylesheet that can be used to format the XML file to the Html format.

    When we want the XML file to be outputed to be Html format, we need to involve the prepared XSL file in XML file like below:

    <?xml-stylesheet type="text/xsl" href="1.xsl"?>

    If we add it in XML file, we can double click the XML file, and then we can see the html format output in the explore.

    Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    Wednesday, October 02, 2013 5:56 AM