Jumat, 26 Desember 2025

Membuat Web pakai XML File



path.xml

<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="path.xsl"?>
<Data>
  <Object Name="Outer Object" >
    <Property Name="Outer Property" >
      <Value>Outer Property has a value</Value>
    </Property >

    <Object Name="ObjectA" >
      <Property Name="PropertyA" >
        <Value>Object A Property A has a value</Value>
      </Property >
    </Object>

    <Object Name="ObjectB" >
      <Property Name="PropertyA" >
        <Value>Object B Property A has a value</Value>
      </Property >
    </Object>

  </Object>
</Data>


 ===============================================

path.xsl

 

<?xml version="1.0"?>

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



<xsl:template match="/">

  <HTML>

    <HEAD><TITLE></TITLE></HEAD>

    <BODY>

      <xsl:apply-templates select="Data/Object" />

    </BODY>

  </HTML>

</xsl:template>


<xsl:template match="Object">    

  Object is <xsl:value-of select="@Name"/>

  <OL>

  <xsl:apply-templates select="Property" />

  </OL>

  <xsl:apply-templates select="Object" />     

</xsl:template>


<xsl:template match="Property" >

  <LI><xsl:value-of select="@Name"/> = <xsl:value-of select="Value"/>

  <P>Path to property is

  <xsl:call-template name="fullpath"/>

  </P>

  </LI>

</xsl:template>



<xsl:template name="fullpath">

  <xsl:for-each select="ancestor::*[1]">

    <xsl:call-template name="fullpath"/>

  </xsl:for-each>

  <xsl:text>/</xsl:text>

  <xsl:choose>

    <xsl:when test="@Name">

      <xsl:value-of select="@Name"/>

    </xsl:when>

    <xsl:otherwise>     

      <xsl:value-of select="name()"/> 

    </xsl:otherwise>

  </xsl:choose>

</xsl:template>


</xsl:stylesheet>




Tidak ada komentar: