0

I am brand new to XSL and am trying to get the information from a source file that is in this format:

<mailList>
    <subscriber familyname="Smith"
                givenname="Jon"
                email="[email protected]"/>
    <subscriber givenname="Luke"
                familyname="Sky"
                email="sov.com"/>

I have tried to use value-of but it just creates an empty element:

<xsl:template match="subscriber">
    <xsl:element name="entry">
      <xsl:element name="firstname">
        <xsl:value-of select="forename"></xsl:value-of>
      </xsl:element>

Any help would be greatly appreciated!

1 Answer 1

1

<xsl:template match="subscriber"> is fine for matching any of the subscriber input elements. Inside of that template you can select the data with e.g. xsl:value-of, but of course you have to select existing data, your attempt of select="forename" tries to select a child element of that name. Your subscriber elements don't have any child elements at all, there are only attributes, even those don't have that name forename.

To select an attribute you use e.g. select="@attribute-name", so for your sample e.g. select="@givenname".

As for creating result elements, while <xsl:element name="entry"> is possible, you can use literal result elements e.g.

  <entry>
    <firstname>
      <xsl:value-of select="@givenname"/>
    </firstname>
  </entry>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.