Choosing data from XML using XSLT?

Ok, so I have product.xml and product.xsl

In product.xml they say that I have two bits of data

<productInfo productID="Product1">
<title>Product One</title>
</productInfo>

<productInfo productID="Product2">
<title>Product Two</title>
</productInfo>

In my product.xsl, can I only display one data set depending on the productID parameter?

So, if product.xml was loading as product.xml? productID = Product1 , how can I show only Product1 data?

I tried to get the productID value from the url but this does not work.

<xsl:param name="productID" />
<xsl:value-of select="$productIDParam"/>

Am I trying to do this simply using XML and XSLT?

+3
source share
2 answers

So, if product.xml is loading as product.xml? productID = Product1

How can I only display Product1 data?

I tried to get the productID value from the URL, but this does not work.

<xsl:param name="productID" />
<xsl:value-of select="$productIDParam"/> 

, , XML XSLT?

"productId", .

XSLT- API . , .NET XslCompiledTransform , XsltArgumentList Transform().

:

using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

public class Sample {

   public static void Main() {

      // Create the XslCompiledTransform and load the style sheet.
      XslCompiledTransform xslt = new XslCompiledTransform();
      xslt.Load("discount.xsl");

      // Create the XsltArgumentList.
      XsltArgumentList argList = new XsltArgumentList();

      // Calculate the discount date.
      DateTime orderDate = new DateTime(2004, 01, 15);
      DateTime discountDate = orderDate.AddDays(20);
      argList.AddParam("discount", "", discountDate.ToString());

      // Create an XmlWriter to write the output.             
     XmlWriter writer = XmlWriter.Create("orderOut.xml");

     // Transform the file.
     xslt.Transform(new XPathDocument("order.xml"), argList, writer);
     writer.Close();

  }

}

XSLT , .

+1

XSLT xsl:param, XSLT-, API- XSLT-. URL-, ( , , Javascript /, ASP.NET, Servlet, PHP ), API, ). , XSLT.

0

Source: https://habr.com/ru/post/1783249/


All Articles