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 7637421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:56:05+00:00 2026-05-31T07:56:05+00:00

I have the following xml file: <root> <sub type=print>print</sub> <sub type=email>email</sub> </root> I want

  • 0

I have the following xml file:

<root>
  <sub type="print">print</sub>
  <sub type="email">email</sub>
</root>

I want to match each type up against the following list:

<types>
  <type>email</type>
  <type>broadcast</type>
  <type>mobile</type>
  <type>print</type>
  <type>web</type>
</types>

Using this xslt with the “doc” being the xml and “types” the list above passed in as parameters:

<xsl:stylesheet 
  xmlns = "http://www.w3.org/1999/xhtml"
  xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" 
  version="2.0">

  <xsl:output method="xhtml" indent="yes" />

  <xsl:param name="doc"/>
  <xsl:param name="types"/>   

  <xsl:template match="/">
    <xsl:for-each select="$doc//sub">
      <xsl:variable name="count">
        <xsl:number value="position()" format="1"/>
      </xsl:variable>

      <ul>
        <xsl:for-each select="$types//type">
          <xsl:choose>
            <xsl:when test="$doc//sub[$count]/@type = text()">
              <li>
                <b>
                  <xsl:value-of select="$doc//sub[$count]/@type"/> - <xsl:value-of select="text()"/>
                </b>
              </li>
            </xsl:when>
            <xsl:otherwise>
              <li>
                <xsl:value-of select="$doc//sub[$count]/@type"/> - <xsl:value-of select="text()"/>
              </li>
            </xsl:otherwise>
          </xsl:choose> 
        </xsl:for-each>
      </ul>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

This should give me an unordered list for each sub in my xml printing the type from the sub and then each type. When the sub and the type match, it should be bold. I want this:

<ul>
  <li>print - email</li>
  <li>print - broadcast</li>
  <li>print - mobile</li>
  <li><b>print - print</b></li>
  <li>print - web</li>
</ul>
<ul>
  <li><b>email - email</b></li>
  <li>email - broadcast</li>
  <li>email - mobile</li>
  <li>email - print</li>
  <li>email - web</li>
</ul>

But I get this:

<ul>
  <li><b>print email - email</b></li>
  <li>print email - broadcast</li>
  <li>print email - mobile</li>
  <li><b>print email - print</b></li>
  <li>print email - web</li>
</ul>
<ul>
  <li><b>print email - email</b></li>
  <li>print email - broadcast</li>
  <li>print email - mobile</li>
  <li><b>print email - print</b></li>
  <li>print email - web</li>
</ul>

Thanks for any and all help.

  • 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-31T07:56:07+00:00Added an answer on May 31, 2026 at 7:56 am

    I think it might have something to do with the multiple uses of //.

    Try replacing your root template (match="/") with this:

      <xsl:template match="/">
        <html>
          <xsl:for-each select="$doc/root/sub">
            <xsl:variable name="vType" select="@type"/>
            <ul>
              <xsl:for-each select="$types/types/type">
                <li>
                  <xsl:choose>
                    <xsl:when test=".=$vType">
                      <b>
                        <xsl:value-of select="concat($vType,' - ',.)"/>
                      </b>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="concat($vType,' - ',.)"/>
                    </xsl:otherwise>
                  </xsl:choose>            
                </li>
              </xsl:for-each>
            </ul>
          </xsl:for-each>      
        </html>
      </xsl:template>
    

    NOTE: I added the <html> tag to keep my output well-formed when testing.

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

Sidebar

Related Questions

I have following type of file contains in xml format <?xml version=1.0 encoding=UTF-8?> <root>
I have the following very simple XML file and I want to quickly parse
I have the following xml file and want to parse it into an .aspx
I have the following xml file: <?xml version=1.0 encoding=utf-8?> <root> <phrase id=test><![CDATA[test]]></phrase> <phrase id=test0><![CDATA[test0]]></phrase>
I have the following XML: <root> <book> <element2 location=file.txt/> <element3> <element3child/> </element3> </book> <book>
I have an XML file with the following structure: <root> <subroot id=someID> <val1 value=a/>
I have an XML file of the following structure: <?xml version=1.0 encoding=utf-8?> <root> <ArrayOfLocationDTO
I have an XML file of the following structure <Root> <Child Name=First> <Data Name=a
I have the following xml file: <xfa:data> <form1> <Page1> <Page2> <contractInfo> ... </contractInfo> <paymentInfo>
I have the following in an XML file: <entry> ... <link href=http://www.example.com/somelink /> ...

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.