我是ASP.Net的新手。我创建了一个博客,该帖子页面通过使用XSLT转换博客的xml数据来显示所有帖子。但是,每当用户单击所需的文章时,我都在努力创建专用的帖子页面。
这是xslt代码,用于将博客文章的xml数据转换为首页:
<xsl:for-each select="Posts/post">
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<div class="post-preview">
<a href="Post.aspx">
<h2 class="post-title">
<xsl:value-of select="title"/>
</h2>
<h3 class="post-subtitle">
<xsl:value-of select="subtitle"/>
</h3>
</a>
<p class="post-meta">
Posted by
<xsl:value-of select="author"></xsl:value-of>
on <xsl:value-of select="date"/>
</p>
</div>
<hr/>
</div>
</div>
</div>
</xsl:for-each>>
这是我希望在用户单击所需文章时显示的帖子页面:
但是,我很难获得带有在发布页面的page_load中设置的代码的响应查询字符串。
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["pid"] != null) { }
XmlDocument xml_doc = new XmlDocument();
postdata.DocumentSource = "~/Data/blog_post.xml";
postdata.TransformSource = "~/XSLT file/ViewCurrentPost.xslt";
System.Xml.Xsl.XsltArgumentList xslArg = new System.Xml.Xsl.XsltArgumentList();
xslArg.AddParam("_pid", "", Request.QueryString["pid"]);
postdata.TransformArgumentList = xslArg;
xml_doc.Load(MapPath("~/blog_posts.xml"));
}
这是我制作的XSL文件,用于显示正确的帖子:
<xsl:apply-templates select="Posts/post"/>
<xsl:for-each select ="Posts/post">
<xsl:if test="@pid=$_pid">
<!--Header-->
<header class="masthead" style="background-image: url('img/post-bg.jpg')">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<div class="post-heading">
<h1>
<xsl:value-of select="title"/>
</h1>
<h2 class="subheading">
<xsl:value-of select="subtitle"/>
</h2>
<span class="meta">
Posted by
<xsl:value-of select="author"></xsl:value-of>
on <xsl:value-of select="date"/>
</span>
</div>
</div>
</div>
</div>
</header>
这是我的博客文章结构:
<Posts>
<post pid="pid2623">
<title>Test</title>
<description>Test</description>
<subtitle>Test</subtitle>
<date>7/29/2018 12:00:00 AM</date>
<author>est</author>
</post>
<Posts>