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

  • Home
  • SEARCH
  • 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 3602000
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:41:27+00:00 2026-05-18T20:41:27+00:00

I have an XML file with this format: <?xml version=1.0 encoding=utf-8 ?> <OpacResult> <valueObjects

  • 0

I have an XML file with this format:

<?xml version="1.0" encoding="utf-8" ?>
<OpacResult>
<valueObjects class="list">
    <Catalog>
        <notes>
            Daily newsletter available via e-mail.&#xd;
            IP authenticated. Login not needed within firm.
        </notes>
        <title>Health law360. </title>
        <url>http://health.law360.com/</url>
        <catalogTitles class="list">
            <CatalogTitle>
                <uuid>e5e2bc53ac1001f808cddc29f93ecad8</uuid>
                <timeChanged class="sql-timestamp">2010-12-14 09:17:10.707</timeChanged>
                <timeEntered class="sql-timestamp">2010-12-14 09:17:10.707</timeEntered>
                <whoChanged>B23DE2FFE8DD49B0B0A03D1FEB3E7DA2</whoChanged>
                <whoEntered>B23DE2FFE8DD49B0B0A03D1FEB3E7DA2</whoEntered>
                <updateSearchIndex>true</updateSearchIndex>
                <corpId>RopesGray</corpId>
                <catalogUuid>a20b6b4bac1001f86d28280ed0ebeb9e</catalogUuid>
                <type>O</type>
                <title>Law 360. Health law.</title>
            </CatalogTitle>
            <CatalogTitle>
                <uuid>e5e2bc53ac1001f808cddc299ddfe49d</uuid>
                <timeChanged class="sql-timestamp">2010-12-14 09:17:10.707</timeChanged>
                <timeEntered class="sql-timestamp">2010-12-14 09:17:10.707</timeEntered>
                <whoChanged>B23DE2FFE8DD49B0B0A03D1FEB3E7DA2</whoChanged>
                <whoEntered>B23DE2FFE8DD49B0B0A03D1FEB3E7DA2</whoEntered>
                <updateSearchIndex>true</updateSearchIndex>
                <corpId>RopesGray</corpId>
                <catalogUuid>a20b6b4bac1001f86d28280ed0ebeb9e</catalogUuid>
                <type>O</type>
                <title>Health law 360</title>
            </CatalogTitle>
            <CatalogTitle>
                <uuid>e5e2bc53ac1001f808cddc29ec1d959b</uuid>
                <timeChanged class="sql-timestamp">2010-12-14 09:17:10.707</timeChanged>
                <timeEntered class="sql-timestamp">2010-12-14 09:17:10.707</timeEntered>
                <whoChanged>B23DE2FFE8DD49B0B0A03D1FEB3E7DA2</whoChanged>
                <whoEntered>B23DE2FFE8DD49B0B0A03D1FEB3E7DA2</whoEntered>
                <updateSearchIndex>true</updateSearchIndex>
                <corpId>RopesGray</corpId>
                <catalogUuid>a20b6b4bac1001f86d28280ed0ebeb9e</catalogUuid>
                <type>O</type>
                <title>Health law three hundred sixty</title>
            </CatalogTitle>
        </catalogTitles>
        <catalogUrls class="list"/>
        <gmd>
            <uuid>f8f123acc0a816070192e296a6a71715</uuid>
            <timeChanged class="sql-timestamp">2006-10-10 15:23:37.813</timeChanged>
            <timeEntered class="sql-timestamp">2005-01-27 00:00:00.0</timeEntered>
            <whoChanged>25db9fcd3fd247f4a20485b40cc134ad</whoChanged>
            <whoEntered>user</whoEntered>
            <updateSearchIndex>true</updateSearchIndex>
            <corpId>RopesGray</corpId>
            <isRuleDefault>false</isRuleDefault>
            <ruleName>text</ruleName>
            <term>electronic resource</term>
            <preferCollection>false</preferCollection>
            <isTechnicalManual>false</isTechnicalManual>
            <sip2IsMagnetic>false</sip2IsMagnetic>
        </gmd>
        <issues class="list"/>
    </Catalog>
</valueObjects>
</OpacResult>

As you can see, there are other elements under sibling nodes, but I don’t care about these and only want to see the first one.

I’m using this code to call a template with the string of desired elements as the parameter
and a template to loop through the asterisk-delimited string parameter: (title*url*notes*)

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="columns" />
<xsl:template match="/OpacResult/valueObjects">
    <html>
        <body>
            <table border="1">

                <!-- Header row -->
                <tr>
                    <xsl:call-template name="print-headers">
                        <xsl:with-param name="columns" select="$columns"/>
                    </xsl:call-template>
                </tr>

                <!-- Value rows -->
                <xsl:for-each select="Catalog">
                    <tr>
                        <xsl:call-template name="print-values">
                            <xsl:with-param name="columns" select="$columns"/>
                        </xsl:call-template>
                    </tr>
                </xsl:for-each>
            </table>
        </body>
    </html>
</xsl:template>

<!-- Split up string of column names and create header field names based on element names-->
<xsl:template name="print-headers">
    <xsl:param name="columns"/>

    <xsl:variable name="newList" select="$columns"/>
    <xsl:variable name="first" select="substring-before($newList, '*')" />
    <xsl:variable name="remaining" select="substring-after($newList, '*')" />

    <th>
        <xsl:apply-templates select="Catalog/*[name()=$first]">
            <xsl:with-param name="header">true</xsl:with-param>
        </xsl:apply-templates>
    </th>

    <xsl:if test="$remaining">
        <xsl:call-template name="print-headers">
            <xsl:with-param name="columns" select="$remaining"/>
        </xsl:call-template>
    </xsl:if>

</xsl:template>

<xsl:template name="print-values">
    <xsl:param name="columns"/>

    <xsl:variable name="newList" select="$columns"/>
    <xsl:variable name="first" select="substring-before($newList, '*')" />
    <xsl:variable name="remaining" select="substring-after($newList, '*')" />

    <td>
        <xsl:apply-templates select="Catalog/*[name()=$first]"/>
    </td>

    <xsl:if test="$remaining">
        <xsl:call-template name="print-values">
            <xsl:with-param name="columns" select="$remaining"/>
        </xsl:call-template>
    </xsl:if>

</xsl:template>

<xsl:template match="title">
    <xsl:param name="header"/>

    <xsl:choose>
        <xsl:when test="$header='true'">
            <xsl:text>Title</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <a>
                <xsl:attribute name="href">
                    <xsl:value-of select="//*[name()='url']"/>
                </xsl:attribute>
                <xsl:value-of select="//*[name()='title']"/>
            </a>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="url">
    <xsl:param name="header"/>

    <xsl:choose>
        <xsl:when test="$header='true'">
            <xsl:text>URL</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <a>
                <xsl:attribute name="href">
                    <xsl:value-of select="//*[name()='url']"/>
                </xsl:attribute>
                <xsl:value-of select="//*[name()='url']"/>
            </a>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="notes">
    <xsl:param name="header"/>

    <xsl:choose>
        <xsl:when test="$header='true'">
            <xsl:text>Notes</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="//*[name()='notes']"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="holdingNotes">
    <xsl:param name="header"/>

    <xsl:choose>
        <xsl:when test="$header='true'">
            <xsl:text>Holding Notes</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="//*[name()='holdingNotes']"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="relatedUrl">
    <xsl:param name="header"/>

    <xsl:choose>
        <xsl:when test="$header='true'">
            <xsl:text>Related URL</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="//*[name()='relatedUrl']"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="bibliographicType/hasDataFile">
    <xsl:param name="header"/>

    <xsl:choose>
        <xsl:when test="$header='true'">
            <xsl:text>File</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="Catalog/*[name()='hasDataFile']"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

The only way I can access this template is to use the //*[name()=$first] syntax to extract the value of the element based on the name from the $first parameter.

Any help is greatly appreciated. Thanks very much in advance. Not including the full XML as there are thousands of lines of unnecessary text.

  • 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-18T20:41:28+00:00Added an answer on May 18, 2026 at 8:41 pm

    This stylesheet:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:h="header"
     exclude-result-prefixes="h">
        <h:h>
            <title>Title</title>
            <url>URL</url>
            <notes>Notes</notes>
        </h:h>
        <xsl:param name="pColumns" select="'title url notes'"/>
        <xsl:template match="/OpacResult/valueObjects">
            <html>
                <body>
                    <table border="1">
                        <tr>
                            <xsl:apply-templates
                                 select="document('')/*/h:h"
                                 mode="filter"/>
                        </tr>
                        <xsl:apply-templates/>
                    </table>
                </body>
            </html>
        </xsl:template>
        <xsl:template match="Catalog">
            <tr>
                <xsl:call-template name="filter"/>
            </tr>
        </xsl:template>
        <xsl:template match="h:h/*">
            <th>
                <xsl:value-of select="."/>
            </th>
        </xsl:template>
        <xsl:template match="Catalog/*">
            <td>
                <xsl:value-of select="."/>
            </td>
        </xsl:template>
        <xsl:template match="node()" mode="filter" name="filter">
            <xsl:apply-templates select="*[contains(
                                              concat(' ',$pColumns,' '),
                                              concat(' ',name(),' '))]">
                <xsl:sort select="substring-before(
                                     concat(' ',$pColumns,' '),
                                     concat(' ',name(),' '))"/>
            </xsl:apply-templates>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <html>
        <body>
            <table border="1">
                <tr>
                    <th>Title</th>
                    <th>URL</th>
                    <th>Notes</th>
                </tr>
                <tr>
                    <td>Health law360. </td>
                    <td>http://health.law360.com/</td>
                    <td>             Daily newsletter available via e-mail.
                 IP authenticated. Login not needed within firm.         </td>
                </tr>
            </table>
        </body>
    </html>
    

    Note: Inline data for headers, pseudo sequence parameter for filtering and sorting, modes not for processing the same element in different way but for processing different elements in the same way also.

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

Sidebar

Related Questions

I have an XML file with this format: <?xml version=1.0 encoding=utf-8 ?> <OpacResult> <valueObjects
I have this xml file <?xml version=1.0 encoding=UTF-8?> <bo:C837ClaimParent xsi:type=bo:C837ClaimParent xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:bo=http://somelongpathHere/process/bo> <claimAux> ...
I have an XML file looks like this: <?xml version=1.0 encoding=utf-8 ?> <PathMasks> <Mask
I have an XML file with this structure: <?xml version=1.0 encoding=utf-8 ?> <Photobank> <Landowner
I have an XML document in this format: <?xml version=1.0 encoding=utf-8 ?> <SupportedServices> <Service>
Say I have an XML file which looks like this: <?xml version=1.0 encoding=UTF-8?> <Project
How can I create xml file with this format using c#? <?xml version=1.0 encoding=utf-8
I have an xml document like this: <?xml version=1.0 encoding=utf-8 ?> <demographics> <country id=1
I have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <xs:msgdata xmlns:xs=http://www.myCompany.com
I have document <?xml version=1.0 encoding=utf-8 ?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd>

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.