ฉันเพิ่งเริ่มใช้ XSLT ดังนั้นเราจะขอบคุณสำหรับความช่วยเหลือจริงๆ ฉันค้นหา stackoverflow มามาก พยายามใช้หลายวิธี แต่ล้มเหลว
ฉันมี xml เช่นนี้:
<?xml version="1.0" encoding="utf-8"?>
<asset_detail>
<asset id="1" show_type="Movies">
<title><![CDATA[Movie]]></title>
<media_list>
<media id="11" title="" type="trailer">
<version format="m3u8" rel_path="/Content/movie.m3u8"/>
<version format="HLS" rel_path="/movies/movie.m3u8"/>
</media>
</media_list>
</asset>
</asset_detail>
ฉันควรคัดลอก xml ทั้งหมดและ:
if media_list/media/version/@format = '**HLS**' I need to replace **@rel_path** with
value: **concat**(existing value of **@rel_path****,** **someVariable**
(I'm passing to xsl as a <xsl:param>)
ฉันคิดว่าฉันต้องใช้สิ่งที่ชอบ:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:param name="someVariable"/>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="media/version">
<xsl:attribute name="rel_path">
<xsl:choose>
<xsl:when test="./@format = HLS">
<xsl:value-of select="concat(rel_path,$someVariable)">
</xsl:when>
</xsl:choose>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
ฉันรู้ว่ามันใช้งานไม่ได้ :)