Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Fetching album node from xml

Fetching Album node from xml

Hi,

Im my attached xml from xslt, I need to fetch Album node where id="tcm:501-638216".

Also, I need to pass this id as parameter in the xslt

So the result should be as below from attached xml

<Album name="Delhi Gallery" sno="2" id="tcm:501-638216">
      <Media>
        <Image sno="1">
          <description>The Burj Image-Asit</description>
          <thumbnail>/Preview/staging/sevens/Images/Burj_Khalifa.jpg</thumbnail>
          <bigImage>/Preview/staging/sevens/Images/Burj_Khalifa.jpg</bigImage>
          <link></link>
        </Image>
        <Image sno="2">
          <description>The Burj1 Image</description>
          <thumbnail>/Preview/staging/sevens/Images/Burj_Khalifa.jpg</thumbnail>
          <bigImage>/Preview/staging/sevens/Images/Burj_Khalifa.jpg</bigImage>
          <link></link>
        </Image>
        <Image sno="3">
          <description>The Burj2 Image</description>
          <thumbnail>/Preview/staging/sevens/Images/Burj_Khalifa.jpg</thumbnail>
          <bigImage>/Preview/staging/sevens/Images/Burj_Khalifa.jpg</bigImage>
          <link></link>
        </Image>
        <Image sno="4">
          <description>The Burj3 Image</description>
          <thumbnail>/Preview/staging/sevens/Images/Burj_Khalifa.jpg</thumbnail>
          <bigImage>/Preview/staging/sevens/Images/Burj_Khalifa.jpg</bigImage>
          <link></link>
        </Image>
      </Media>
    </Album>

Please guide

Many Thanks
ImageGallery.xml
0
tia_kamakshi
Asked:
tia_kamakshi
  • 2
1 Solution
 
Geert BormansCommented:
below stylesheet takes a parametyer ($id) and returns the node with that particular id

I used a key for efficientcy of the selection

how you pass the parameter to the XSLT depends on how you call the XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="1.0">
    <xsl:param name="id" select="'tcm:501-638216'"/>
    
    <xsl:key name="by-id" match="*" use="@id"/>
    
    <xsl:template match="/">
        <xsl:copy-of select="key('by-id', $id)"/>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0
 
tia_kamakshiAuthor Commented:
Many Thanks Gertone.

Its really works good. Just wanted to know what below code will do
 exclude-result-prefixes="xs"


Thanks again

0
 
Geert BormansCommented:
I will assure that you won't see xml:xs="..." in your result tree if you dont have xs:foo nodes
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now