이 질문은 비슷한 것으로 나온 두 가지 답변을 보았지만 내 문제를 해결하지 못했다는 사실에서 독특합니다. timeShift 필드를 태그의 속성이 아닌 텍스트 값으로 html에 추가하고 싶습니다.
다음 xml이 있으며 HH : MM : SS 형식이되도록 timeShift 필드에서 시간 조작을 수행하고 싶습니다.
xsl에서 어떻게 할 수 있습니까?
다음은 내 현재 xsl 파일입니다.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:key name="party" match="newParty" use="@userId" />
<xsl:template match="/chatTranscript">
<html>
<head><link rel="stylesheet" type="text/css" href="/webrecall/css/chat.css"/></head>
<header>Chat - <xsl:value-of select="@sessionId" /> - <xsl:value-of select="@startAt" /></header>
<xsl:apply-templates/>
</html>
</xsl:template>
<xsl:template match="newParty[userInfo/@userType='CLIENT']">
<div class="ClientJoined" id="{@userId}">
<label>Client: <xsl:value-of select="userInfo/@userNick" /></label>
<label class="timeShiftLabel"><xsl:value-of select="@timeShift" /></label>
</div>
</xsl:template>
<xsl:template match="newParty[userInfo/@userType='AGENT']">
<div class="AgentJoined" id="{@userId}">
<label>Agent: <xsl:value-of select="userInfo/@userNick" /></label>
<label class="timeShiftLabel"><xsl:value-of select="@timeShift" /></label>
</div>
</xsl:template>
<xsl:template match="message">
<xsl:variable name="party-class">
<xsl:call-template name="lookup-class"/>
</xsl:variable>
<div class="Messages {$party-class}" id="{@eventId}">
<label><xsl:value-of select="msgText" /></label>
<label class="timeShiftLabel"><xsl:value-of select="@timeShift" /></label>
</div>
</xsl:template>
<xsl:template match="notice">
<xsl:variable name="party-class">
<xsl:call-template name="lookup-class"/>
</xsl:variable>
<div class="Notices {$party-class}" id="{@eventId}">
<label><xsl:value-of select="noticeText" /></label>
<label class="timeShiftLabel"><xsl:value-of select="@timeShift" /></label>
</div>
</xsl:template>
<xsl:template match="partyLeft">
<xsl:variable name="party-class">
<xsl:call-template name="lookup-class"/>
</xsl:variable>
<div class="Notices {$party-class}" id="{@eventId}">
<label><xsl:value-of select="reason" /></label>
<label class="timeShiftLabel"><xsl:value-of select="@timeShift" /></label>
</div>
</xsl:template>
<xsl:template name="lookup-class">
<xsl:variable name="party-type" select="key('party', @userId)/userInfo/@userType" />
<xsl:choose>
<xsl:when test="$party-type='CLIENT'">Client</xsl:when>
<xsl:when test="$party-type='AGENT'">Agent</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
다음은 xml입니다.
<?xml version="1.0"?><chatTranscript startAt="2015-06-04T09:07:40Z" sessionId="0003CaANX11G00HD">
<newParty userId="00955570155B0000" eventId="1" timeShift="0" visibility="ALL">
<userInfo personId="" userNick="PhilC" userType="CLIENT" protocolType="FLEX" timeZoneOffset="120"/>
<userData>
<item key="EmailAddress"/>
<item key="FirstName">Phil</item>
<item key="IdentifyCreateContact">3</item>
<item key="LastName">Collins</item>
<item key="MediaType">chat</item>
</userData>
</newParty>
<newParty userId="0095557015600002" eventId="2" timeShift="4" visibility="ALL">
<userInfo personId="" userNick="system" userType="EXTERNAL" protocolType="ESP" timeZoneOffset="0"/>
</newParty>
<message userId="0095557015600002" eventId="3" timeShift="4" visibility="ALL">
<msgText>agent will be with you shortly</msgText>
</message>
<newParty userId="00955570156E0003" eventId="4" timeShift="19" visibility="ALL">
<userInfo personId="emailqa" userNick="emailqa" userType="AGENT" protocolType="BASIC" timeZoneOffset="120"/>
</newParty>
<message userId="00955570155B0000" eventId="6" timeShift="22" visibility="ALL">
<msgText msgType="text" treatAs="NORMAL">hellO?</msgText>
</message>
<message userId="00955570156E0003" eventId="9" timeShift="26" visibility="ALL">
<msgText treatAs="NORMAL">hi Phil</msgText>
</message>
<message userId="00955570156E0003" eventId="11" timeShift="28" visibility="ALL">
<msgText treatAs="NORMAL">whatsup?</msgText>
</message>
<message userId="00955570155B0000" eventId="14" timeShift="45" visibility="ALL">
<msgText msgType="text" treatAs="NORMAL">we're sitting next to each other but we're sending IMs </msgText>
</message>
<message userId="00955570156E0003" eventId="17" timeShift="54" visibility="ALL">
<msgText treatAs="NORMAL">hehehe</msgText>
</message>
<message userId="00955570156E0003" eventId="19" timeShift="56" visibility="ALL">
<msgText treatAs="NORMAL">indeed</msgText>
</message>
<partyLeft userId="00955570156E0003" askerId="00955570156E0003" eventId="21" timeShift="77" visibility="ALL">
<reason code="1">left with request to close if no agents</reason>
</partyLeft>
<partyLeft userId="00955570155B0000" askerId="00955570156E0003" eventId="22" timeShift="77" visibility="ALL">
<reason code="4">removed by other party</reason>
</partyLeft>
</chatTranscript>
따라서 질문은 timeShift 정수 값을 입력 (초 단위로 경과 한 시간을 나타냄)으로 가져와 HH : mm : ss 형식의 기간으로 조작하는 방법입니다.
다음 기능에 대한 설명을 익히십시오.
substring
-문자열의 일부를 얻고,xs:time(timestring)
-문자열을 xs : time 유형 으로 캐스팅 ,format-time
-xs : time 변수 에서 형식화 된 문자열을 가져옵니다 .위의 함수는 특히 시간 값에 대해 일부 계산을 수행하려는 경우 유용 할 수 있습니다.
또 다른 해결책은 substring
함수를 사용하여 소스 문자열 (예 :시, 분 및 초 부분)에서 필요한 부분 문자열을 추출하는 것입니다. 그런 다음 concat
함수를 사용하여 출력 문자열을 만들 수 있습니다 .
아래에 주어진 예를 만들었습니다.
<?xml version="1.0" encoding="UTF-8"?>
<Main>
<Record timeShift="17" cause="A1">Abcd efgh ijlk</Record>
<Record timeShift="85" cause="A2">Mnop qrst uvw xyz</Record>
</Main>
아래에는 timeShift
속성을 mm:ss
형식으로 변환하는 XSL 예제가 있습니다 .
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="@timeShift">
<xsl:attribute name="timeShift">
<xsl:call-template name="format-duration"/>
</xsl:attribute>
</xsl:template>
<xsl:template name="format-duration">
<xsl:param name="value" select="." />
<xsl:param name="alwaysIncludeHours" select="false()" />
<xsl:param name="includeSeconds" select="true()" />
<xsl:if test="$value > 3600 or $alwaysIncludeHours">
<xsl:value-of select="concat(format-number($value div 3600, '00'), ':')"/>
</xsl:if>
<xsl:value-of select="format-number($value div 60 mod 60, '00')" />
<xsl:if test="$includeSeconds">
<xsl:value-of select="concat(':', format-number($value mod 60, '00'))" />
</xsl:if>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>
</xsl:stylesheet>
format-duration
템플릿은 이 게시물에 대한 댓글에 언급 된 XSLT의 초에서 시간으로 복사됩니다 .
XSL 소스로 돌아갑니다.
<label class="timeShiftLabel"><xsl:value-of select="@timeShift" /></label>
에:
<label class="timeShiftLabel">
<xsl:call-template name="format-duration">
<xsl:with-param name="value" select="@timeShift"/>
<xsl:with-param name="alwaysIncludeHours" select="true()" />
</xsl:call-template>
</label>
물론 format-duration
템플릿 을 호출하므로 XSL에도 포함해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다