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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:41:59+00:00 2026-06-14T02:41:59+00:00

I am beginner in XSLT. My Source XML: <Request> <Documents> <Doc Type=A>123</Doc> <Doc Type=C>345</Doc>

  • 0

I am beginner in XSLT.
My Source XML:

<Request>
   <Documents>
      <Doc Type="A">123</Doc>
      <Doc Type="C">345</Doc>
   </Documents>
</Request>

My response XML:

<Response>
   <RequestedDoc>
       <Doc Type="A">123</Doc>
       <Doc Type="C">345</Doc>
   </RequestedDoc>
   <Result>
      <Document>
         <Id>A123</Id>
         <Name>Doc1</Name>
      </Document>
      <Document>
         <Id>E143</Id>
         <Name>Doc2</Name>
      </Document>
      <Document>
         <Id>C345</Id>
         <Name>Doc3</Name>
      </Document>
      <Document>
         <Id>D153</Id>
         <Name>Doc4</Name>
      </Document>
   </Result>
</Response>

i need to filter the Result tag using the RequestedDoc tag.
i have tried below XSLT but it returns only the 1st result.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:output method="xml" indent="yes" />
   <xsl:variable name="requestedDoc" select="//RequestedDoc/Doc"/>

   <xsl:template match="Response">
      <xsl:element name="FilterResult">
          <xsl:apply-templates select="//Result/Document[contains(Id,$requestedDoc)]"/>
      </xsl:element>
   </xsl:template>

   <xsl:template match="Document">
      <xsl:element name="Name">
         <xsl:value-of select="Name"/>
      </xsl:element>
   </xsl:template>
</xsl:stylesheet>

but this XSLT always return data for first Doc A123.

<FilterResult>
  <Name>Doc1</Name>
</FilterResult>

Expected result is

<FilterResult>
  <Name>Doc1</Name>
  <Name>Doc3</Name>
</FilterResult>

Please 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-06-14T02:42:00+00:00Added an answer on June 14, 2026 at 2:42 am

    This transformation:

    <xsl:stylesheet version="1.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="/*">
         <FilterResult>
          <xsl:apply-templates/>
         </FilterResult>
     </xsl:template>
    
     <xsl:template match="Document[substring(Id,2) = /*/RequestedDoc/*]">
      <xsl:copy-of select="Name"/>
     </xsl:template>
     <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    when applied on the provided Response document:

    <Response>
       <RequestedDoc>
           <Doc Type="A">123</Doc>
           <Doc Type="C">345</Doc>
       </RequestedDoc>
       <Result>
          <Document>
             <Id>A123</Id>
             <Name>Doc1</Name>
          </Document>
          <Document>
             <Id>E143</Id>
             <Name>Doc2</Name>
          </Document>
          <Document>
             <Id>C345</Id>
             <Name>Doc3</Name>
          </Document>
          <Document>
             <Id>D153</Id>
             <Name>Doc4</Name>
          </Document>
       </Result>
    </Response>
    

    produces the wanted, correct result:

    <FilterResult>
       <Name>Doc1</Name>
       <Name>Doc3</Name>
    </FilterResult>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am beginner in XSLT. My Source XML is as below <Options> <Option> <Data>Data1</Data>
I am a beginner to XSLT. My Source XML is as below: <Passengers> <Passenger
I'm a beginner at XSL FO. I have a very simple XML document :
I am a beginner and want to learn XSLT. I came upon an issue
Beginner question. My goal is to add documents to my CouchDB database on a
I have JDK6 and using JAXP for the transformation. I am beginner to XSLT.
I have next xml: <page> <document> <id>1001</id> <cur>USD</cur> <date>01.01.2009</date> <amount>10</amount> </document> <document> <id>1001</id> <cur>USD</cur>
First, I should say that I am a beginner in terms of XSLT. Although
Possible Duplicate: Add an attribute with static value with xslt I have an XML
The given source xml is part is <EORI_Number>23 March 2002</EORI_Number> and applying style sheet

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.